• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / smartsprites / #43

11 Nov 2023 07:47PM UTC coverage: 88.431%. Remained the same
#43

push

github

hazendaz
[tests] Fix tests given they expected order and now license on everything for +36

1437 of 1625 relevant lines covered (88.43%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/main/java/org/carrot2/labs/smartsprites/message/Message.java
1
/*
2
 * SmartSprites Project
3
 *
4
 * Copyright (C) 2007-2009, Stanisław Osiński.
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without modification,
8
 * are permitted provided that the following conditions are met:
9
 *
10
 * - Redistributions of  source code must  retain the above  copyright notice, this
11
 *   list of conditions and the following disclaimer.
12
 *
13
 * - Redistributions in binary form must reproduce the above copyright notice, this
14
 *   list of conditions and the following  disclaimer in  the documentation  and/or
15
 *   other materials provided with the distribution.
16
 *
17
 * - Neither the name of the SmartSprites Project nor the names of its contributors
18
 *   may  be used  to endorse  or  promote  products derived   from  this  software
19
 *   without specific prior written permission.
20
 *
21
 * - We kindly request that you include in the end-user documentation provided with
22
 *   the redistribution and/or in the software itself an acknowledgement equivalent
23
 *   to  the  following: "This product includes software developed by the SmartSprites
24
 *   Project."
25
 *
26
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  AND
27
 * ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT LIMITED  TO, THE IMPLIED
28
 * WARRANTIES  OF  MERCHANTABILITY  AND  FITNESS  FOR  A  PARTICULAR  PURPOSE   ARE
29
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE  FOR
30
 * ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  DAMAGES
31
 * (INCLUDING, BUT  NOT LIMITED  TO, PROCUREMENT  OF SUBSTITUTE  GOODS OR SERVICES;
32
 * LOSS OF USE, DATA, OR PROFITS;  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND  ON
33
 * ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT  LIABILITY,  OR TORT
34
 * (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY  OUT OF THE USE  OF THIS
35
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
 */
37
package org.carrot2.labs.smartsprites.message;
38

39
import java.io.Serializable;
40
import java.util.Comparator;
41

42
import org.carrot2.labs.smartsprites.SpriteImageDirective;
43
import org.carrot2.labs.smartsprites.SpriteImageDirective.Ie6Mode;
44
import org.carrot2.labs.smartsprites.SpriteImageDirective.SpriteImageFormat;
45
import org.carrot2.labs.smartsprites.SpriteImageDirective.SpriteImageLayout;
46
import org.carrot2.labs.smartsprites.SpriteImageDirective.SpriteUidType;
47
import org.carrot2.labs.smartsprites.SpriteLayoutProperties.SpriteAlignment;
48
import org.carrot2.labs.smartsprites.SpriteReferenceDirective;
49

50
/**
51
 * Represents a processing message, can be an information message or a warning.
52
 */
53
public class Message implements Serializable
54
{
55
    private static final long serialVersionUID = 1L;
56

57
    /**
58
     * The importance of the message.
59
     */
60
    public enum MessageLevel
1✔
61
    {
62
        /**
63
         * Information message, can be ignored.
64
         */
65
        INFO(1),
1✔
66

67
        /**
68
         * Notice messages related to IE6 problems.
69
         */
70
        IE6NOTICE(2),
1✔
71

72
        /**
73
         * Notice messages related to deprecated features.
74
         */
75
        DEPRECATION(2),
1✔
76

77
        /**
78
         * Warning messages, ignoring can lead to the converted designs looking broken.
79
         */
80
        WARN(4),
1✔
81

82
        /**
83
         * Error messages, SmartSprites cannot perform processing.
84
         */
85
        ERROR(5),
1✔
86

87
        /**
88
         * Status messages displayed at the end of processing.
89
         */
90
        STATUS(6);
1✔
91

92
        /** Numeric level for comparisons */
93
        private final int level;
94

95
        private MessageLevel(int level)
96
        {
1✔
97
            this.level = level;
1✔
98
        }
1✔
99

100
        public static final Comparator<MessageLevel> COMPARATOR = new Comparator<MessageLevel>()
1✔
101
        {
1✔
102
            public int compare(MessageLevel levelA, MessageLevel levelB)
103
            {
104
                return levelA.level - levelB.level;
1✔
105
            }
106
        };
107

108
    }
109

110
    /**
111
     * Defines all the possible information and warning messages.
112
     */
113
    public enum MessageType
1✔
114
    {
115
        CANNOT_DETERMINE_IMAGE_FORMAT("Cannot determine image format from file name: %s"),
1✔
116

117
        CANNOT_NOT_LOAD_IMAGE("Cannot load image: %s due to: %s"),
1✔
118

119
        CANNOT_PARSE_MARGIN_VALUE(
1✔
120
            "Cannot parse margin value: %s. Only 'px' units are supported."),
121

122
        CANNOT_WRITE_SPRITE_IMAGE("Cannot write sprite image: %s due to %s"),
1✔
123

124
        CANNOT_CREATE_DIRECTORIES("Cannot create directories: %s"),
1✔
125

126
        CREATING_CSS_STYLE_SHEET("Creating CSS style sheet: %s"),
1✔
127

128
        WRITING_CSS("Writing CSS to %s"),
1✔
129

130
        WRITING_SPRITE_IMAGE("Writing sprite image of size %s x %s for sprite '%s' to %s"),
1✔
131

132
        IGNORING_SPRITE_IMAGE_REDEFINITION("Ignoring sprite image redefinition"),
1✔
133

134
        MALFORMED_CSS_RULE("Malformed CSS rule: %s"),
1✔
135

136
        MALFORMED_COLOR("Malformed color: %s"),
1✔
137

138
        MALFORMED_URL("Malformed URL: %s"),
1✔
139

140
        MALFORMED_SPRITE_IMAGE_PATH("Malformed sprite-image path: %s"),
1✔
141

142
        UNSUPPORTED_VARIABLE_IN_SPRITE_IMAGE_PATH(
1✔
143
            "Unsupported variable in sprite-image path: %s"),
144

145
        MORE_THAN_ONE_RULE_NEXT_TO_SPRITE_REFERENCE_DIRECTIVE(
1✔
146
            "Found more than one CSS rule next to sprite reference comment: %s"),
147

148
        NO_BACKGROUND_IMAGE_RULE_NEXT_TO_SPRITE_REFERENCE_DIRECTIVE(
1✔
149
            "No 'background-image' CSS rule next to sprite reference comment: %s"),
150

151
        EITHER_ROOT_DIR_OR_CSS_FILES_IS_REQUIRED(
1✔
152
            "Either root directory or non-empty list of individual CSS files is required"),
153

154
        ROOT_DIR_AND_CSS_FILES_CANNOT_BE_BOTH_SPECIFIED_UNLESS_WITH_OUTPUT_DIR(
1✔
155
            "Root directory and individual CSS files cannot be both specified, unless output dir is also specified"),
156

157
        ROOT_DIR_IS_REQUIRED_FOR_OUTPUT_DIR(
1✔
158
            "If output directory is specified, root directory must also be provided"),
159

160
        ROOT_DIR_DOES_NOT_EXIST_OR_IS_NOT_DIRECTORY(
1✔
161
            "Root directory must exist and be a directory: %s"),
162

163
        CSS_FILE_DOES_NOT_EXIST("Ignoring CSS file %s, it does not exist"),
1✔
164

165
        CSS_PATH_IS_NOT_A_FILE("Ignoring CSS path %s, it is not a file"),
1✔
166

167
        OUTPUT_DIR_IS_NOT_DIRECTORY("Output directory must be a directory: %s"),
1✔
168

169
        DOCUMENT_ROOT_DIR_DOES_NOT_EXIST_OR_IS_NOT_DIRECTORY(
1✔
170
            "Document root directory must exist and be a directory: %s"),
171

172
        IGNORING_CSS_FILE_OUTSIDE_OF_ROOT_DIR(
1✔
173
            "Ignoring a CSS file outside of root directory: %s"),
174

175
        CSS_FILE_SUFFIX_IS_REQUIRED_IF_NO_OUTPUT_DIR(
1✔
176
            "A non-empty CSS file suffix is required when no output directory is specified"),
177

178
        ONLY_LEFT_OR_RIGHT_ALIGNMENT_ALLOWED(
1✔
179
            "Only 'left' or 'right' alignment allowed on vertical sprites, found: %s. Using 'left'."),
180

181
        ONLY_TOP_OR_BOTTOM_ALIGNMENT_ALLOWED(
1✔
182
            "Only 'top' or 'bottom' alignment allowed on horizontal sprites, found: %s. Using 'top'."),
183

184
        READING_SPRITE_IMAGE_DIRECTIVES("Reading sprite image directives from %s"),
1✔
185

186
        READING_SPRITE_REFERENCE_DIRECTIVES("Reading sprite reference directives from %s"),
1✔
187

188
        READING_CSS("Reading CSS from %s"),
1✔
189

190
        READING_IMAGE("Reading image from %s"),
1✔
191

192
        REFERENCED_SPRITE_NOT_FOUND("Referenced sprite: %s not found"),
1✔
193

194
        SPRITE_ID_NOT_FOUND("'" + SpriteImageDirective.PROPERTY_SPRITE_ID
1✔
195
            + "' rule is required"),
196

197
        SPRITE_IMAGE_URL_NOT_FOUND("'" + SpriteImageDirective.PROPERTY_SPRITE_IMAGE_URL
1✔
198
            + "' rule is required"),
199

200
        SPRITE_REF_NOT_FOUND("'" + SpriteReferenceDirective.PROPERTY_SPRITE_REF
1✔
201
            + "' rule is required"),
202

203
        UNSUPPORTED_ALIGNMENT("Unsupported alignment: %s. Supported alignments are: "
1✔
204
            + SpriteAlignment.valuesAsString() + "."),
1✔
205

206
        UNSUPPORTED_INDIVIDUAL_IMAGE_FORMAT("Unsupported format of image loaded from: %s"),
1✔
207

208
        UNSUPPORTED_SPRITE_IMAGE_FORMAT(
1✔
209
            "Format of image: %s is not supported. Supported formats are: "
210
                + SpriteImageFormat.valuesAsString() + "."),
1✔
211

212
        UNSUPPORTED_LAYOUT("Unsupported layout: %s. Supported layouts are: "
1✔
213
            + SpriteImageLayout.valuesAsString() + "."),
1✔
214

215
        UNSUPPORTED_IE6_MODE("Unsupported ie6 mode: %s. Supported ie6 modes are: "
1✔
216
            + Ie6Mode.valuesAsString() + "."),
1✔
217

218
        UNSUPPORTED_UID_TYPE("Unsupported uid type: %s. Supported uid types are: "
1✔
219
            + SpriteUidType.valuesAsString() + "."),
1✔
220

221
        IGNORING_IE6_MODE(
1✔
222
            "The sprite-ie6-mode applies only to PNG sprites. Ignoring for a %s sprite."),
223

224
        JPG_DOES_NOT_SUPPORT_INDEXED_COLOR("JPG format does not support indexed color"),
1✔
225

226
        TOO_MANY_COLORS_FOR_INDEXED_COLOR(
1✔
227
            "Sprite '%s' requires %d colors, but the maximum for indexed color mode is %d. Image quality will be degraded."),
228

229
        ALPHA_CHANNEL_LOSS_IN_INDEXED_COLOR(
1✔
230
            "Alpha channel of sprite '%s' cannot be encoded in indexed color mode. Image quality will be degraded."),
231

232
        USING_WHITE_MATTE_COLOR_AS_DEFAULT(
1✔
233
            "Defaulting to white matte color to render partial transparencies of sprite '%s'"),
234

235
        IGNORING_MATTE_COLOR_NO_PARTIAL_TRANSPARENCY(
1✔
236
            "Ignoring sprite-mate-color on sprite '%s' because the sprite image does not contain partially transparent areas"),
237

238
        IGNORING_MATTE_COLOR_NO_SUPPORT(
1✔
239
            "Ignoring sprite-mate-color on sprite '%s' because its output format does not require matting or does not support transparency"),
240

241
        IGNORING_NEGATIVE_MARGIN_VALUE("Values of %s must not be negative, using 0"),
1✔
242

243
        PROCESSING_COMPLETED("SmartSprites processing completed in %d ms"),
1✔
244

245
        PROCESSING_COMPLETED_WITH_WARNINGS(
1✔
246
            "SmartSprites processing completed in %d ms with %d warning(s)"),
247

248
        UNSUPPORTED_PROPERTIES_FOUND("Unsupported properties found: %s"),
1✔
249

250
        OVERRIDING_PROPERTY_FOUND(
1✔
251
            "Found a '%s' property that overrides the generated one. Move it before the sprite reference directive on line %d."),
252

253
        ABSOLUTE_PATH_AND_NO_DOCUMENT_ROOT(
1✔
254
            "Found an absolute image path '%s' and no document.root.dir.path was defined. Taking relative to the CSS file."),
255

256
        DEPRECATED_SPRITE_IMAGE_UID(
1✔
257
            "The sprite-image-uid property is deprecated and will be removed in version 0.4.0. Please insert the ${%s} variable into the sprite-image property instead."),
258

259
        FRACTIONAL_SCALE_VALUE("The sprite-scale value applied to '%s' results in a scaled sprite with fractional dimensions (%fpx %fpx)."),
1✔
260

261
        IMAGE_FRACTIONAL_SCALE_VALUE("The sprite-scale value applied to '%s' results in a scaled image with fractional dimensions (%fpx %fpx)."),
1✔
262

263
        GENERIC("%s");
1✔
264

265
        /**
266
         * Human readable text of the message.
267
         */
268
        private String text;
269

270
        private MessageType(String text)
271
        {
1✔
272
            this.text = text;
1✔
273
        }
1✔
274

275
        /**
276
         * Returns a human readable version of this message.
277
         */
278
        public String getText()
279
        {
280
            return text;
×
281
        }
282
    }
283

284
    /**
285
     * Importance of this message.
286
     */
287
    public final MessageLevel level;
288

289
    /**
290
     * Semantics of the message.
291
     */
292
    public final MessageType type;
293

294
    /**
295
     * CSS file to which this message refers or <code>null</code>.
296
     */
297
    public final String cssPath;
298

299
    /**
300
     * Line number to which this message refers, meaningful only if {@link #cssPath} is
301
     * not <code>null</code>.
302
     */
303
    public final int line;
304

305
    /**
306
     * Additional arguments to this message, used to format the human-readable string.
307
     */
308
    public final Object[] arguments;
309

310
    /**
311
     * Creates a new message, see field descriptions for details.
312
     */
313
    public Message(MessageLevel level, MessageType type, String cssPath, int line,
314
        Object... arguments)
315
    {
1✔
316
        this.level = level;
1✔
317
        this.type = type;
1✔
318
        this.cssPath = cssPath;
1✔
319
        this.line = line;
1✔
320
        this.arguments = new Object [arguments.length];
1✔
321
        System.arraycopy(arguments, 0, this.arguments, 0, arguments.length);
1✔
322
    }
1✔
323

324
    public static Message warn(MessageType type, Object... arguments)
325
    {
326
        return new Message(MessageLevel.WARN, type, null, 0, arguments);
1✔
327
    }
328

329
    public static Message error(MessageType type, Object... arguments)
330
    {
331
        return new Message(MessageLevel.ERROR, type, null, 0, arguments);
1✔
332
    }
333

334
    @Override
335
    public String toString()
336
    {
337
        final StringBuilder stringBuilder = new StringBuilder();
×
338

339
        stringBuilder.append(level);
×
340
        stringBuilder.append(": ");
×
341
        stringBuilder.append(getFormattedMessage());
×
342

343
        if (cssPath != null)
×
344
        {
345
            stringBuilder.append(" (");
×
346
            stringBuilder.append(cssPath);
×
347
            stringBuilder.append(", line: ");
×
348
            stringBuilder.append(line + 1);
×
349
            stringBuilder.append(")");
×
350
        }
351

352
        return stringBuilder.toString();
×
353
    }
354

355
    public String getFormattedMessage()
356
    {
357
        return String.format(type.getText(), arguments);
×
358
    }
359
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc