fr.avianey.androidsvgdrawable.maven.SvgDrawableMavenPlugin Maven / Gradle / Ivy
/*
* Copyright 2013, 2014 Antoine Vianey
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.avianey.androidsvgdrawable.maven;
import java.io.File;
import java.util.Map;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import fr.avianey.androidsvgdrawable.BoundsType;
import fr.avianey.androidsvgdrawable.Density;
import fr.avianey.androidsvgdrawable.OutputFormat;
import fr.avianey.androidsvgdrawable.OverrideMode;
import fr.avianey.androidsvgdrawable.SvgDrawablePlugin;
/**
* Goal which generates drawable from Scalable Vector Graphics (SVG) files.
*
* @author antoine vianey
*/
@Mojo(name = "gen")
public class SvgDrawableMavenPlugin extends AbstractMojo implements SvgDrawablePlugin.Parameters {
/**
* Directory of the svg resources to generate drawable from.
*
* @since 1.0.0
*/
@Parameter(required = true)
private File from;
/**
* Location of the Android "./src/main/res/drawable(-.*)" directories :
*
* - drawable
* - drawable-hdpi
* - drawable-ldpi
* - drawable-mdpi
* - drawable-xhdpi
* - drawable-xxhdpi
* - drawable-xxxhdpi
*
*
* @since 1.0.0
*/
@Parameter(defaultValue = "${project.basedir}/src/main/res")
private File to;
/**
* Create a drawable-density directory when no directory exists for the
* given qualifiers.
* If set to false, the plugin will generate the drawable in the best
* matching directory :
*
* - match all of the qualifiers
* - no other matching directory with less qualifiers
*
*
* @since 1.0.0
*/
@Parameter(defaultValue = "true")
private boolean createMissingDirectories;
/**
* Enumeration of desired target densities.
* If no density specified, PNG are only generated to existing directories.
* If at least one density is specified, PNG are only generated in matching
* directories.
*
* @since 1.0.0
*/
@Parameter
private Density[] targetedDensities;
/**
* Use alternatives names for PNG resources
*
* - Key
* - original svg name (without density prefix)
* - Value
* - target name
*
*
* @since 1.0.0
*/
@Parameter
private Map rename;
/**
* Name of the input file to use to generate a 512x512 high resolution
* Google Play icon
*
* @since 1.0.0
*/
@Parameter
private String highResIcon;
/**
* Path to the 9-patch drawable configuration file.
*
* @since 1.0.0
*/
@Parameter
private File ninePatchConfig;
/**
* Path to the .svgmask directory.
* The {@link SvgDrawableMavenPlugin#from} directory will be use if not specified.
*
* @since 1.0.0
*/
@Parameter
private File svgMaskDirectory;
/**
* Path to a directory referencing additional svg resources to be taken in
* account for masking.
* The {@link SvgDrawableMavenPlugin#from} directory will be use if not specified.
*
* @since 1.0.0
*/
@Parameter
private File svgMaskResourcesDirectory;
/**
* Path to the directory where masked svg files are generated.
* "target/generated-svg"
*
* @since 1.0.0
*/
@Parameter(readonly = true, defaultValue = "${project.build.directory}/generated-svg")
private File svgMaskedSvgOutputDirectory;
/**
* If set to true a mask combination will be ignored when a
* .svgmask use the same .svg resources in
* at least two different <image> tags.
*
* @since 1.0.0
*/
@Parameter(defaultValue = "true")
private boolean useSameSvgOnlyOnceInMask;
/**
* Override existing generated resources.
* It's recommended to use {@link OverrideMode#always} for tests and
* production releases.
*
* @since 1.0.0
* @see OverrideMode
*/
@Parameter(defaultValue = "always", alias = "override")
private OverrideMode overrideMode;
/**
*
* USE WITH CAUTION
* You'll more likely take time to set desired width and height properly
*
*
* When <SVG> attributes "x", "y", "width" and "height" are not
* present defines which element are taken in account to compute the Area Of
* Interest of the image. The plugin will output a WARNING log if no width
* or height are specified within the <svg> element.
*
* - all
* - This includes primitive paint, filtering, clipping and masking.
* - sensitive
* - This includes the stroked area but does not include the effects of clipping, masking or filtering.
* - geometry
* - This excludes any clipping, masking, filtering or stroking.
* - primitive
* - This is the painted region of fill and stroke but does not account for clipping, masking or filtering.
*
*
* @since 1.0.0
* @see BoundsType
*/
@Parameter(defaultValue = "sensitive")
private BoundsType svgBoundsType;
/**
* The format for the generated images.
*
* - PNG
* - JPG
*
*
* @since 1.0.0
* @see OutputFormat
*/
@Parameter(defaultValue = "PNG")
private OutputFormat outputFormat;
/**
* The quality for the JPG output format.
*
* @since 1.0.0
*/
@Parameter(defaultValue = "85")
private int jpgQuality;
/**
* The background color to use when {@link OutputFormat#JPG} is specified.
* Default value is 0xFFFFFFFF (white)
*
* @since 1.0.0
*/
@Parameter(defaultValue = "-1")
private int jpgBackgroundColor;
public void execute() {
final SvgDrawablePlugin plugin = new SvgDrawablePlugin(this, new MavenLogger(getLog()));
plugin.execute();
}
@Override
public File getFrom() {
return from;
}
@Override
public File getTo() {
return to;
}
@Override
public boolean isCreateMissingDirectories() {
return createMissingDirectories;
}
@Override
public OverrideMode getOverrideMode() {
return overrideMode;
}
@Override
public Density[] getTargetedDensities() {
return targetedDensities;
}
@Override
public Map getRename() {
return rename;
}
@Override
public String getHighResIcon() {
return highResIcon;
}
@Override
public File getNinePatchConfig() {
return ninePatchConfig;
}
@Override
public File getSvgMaskDirectory() {
return svgMaskDirectory;
}
@Override
public File getSvgMaskResourcesDirectory() {
return svgMaskResourcesDirectory;
}
@Override
public File getSvgMaskedSvgOutputDirectory() {
return svgMaskedSvgOutputDirectory;
}
@Override
public boolean isUseSameSvgOnlyOnceInMask() {
return useSameSvgOnlyOnceInMask;
}
@Override
public OutputFormat getOutputFormat() {
return outputFormat;
}
@Override
public int getJpgQuality() {
return jpgQuality;
}
@Override
public int getJpgBackgroundColor() {
return jpgBackgroundColor;
}
@Override
public BoundsType getSvgBoundsType() {
return svgBoundsType;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy