use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class AbstractSiteRenderingMojo method createSiteRenderingContext.
protected SiteRenderingContext createSiteRenderingContext(Locale locale) throws MojoExecutionException, IOException, MojoFailureException {
DecorationModel decorationModel = prepareDecorationModel(locale);
if (attributes == null) {
attributes = new HashMap<String, Object>();
}
if (attributes.get("project") == null) {
attributes.put("project", project);
}
if (attributes.get("inputEncoding") == null) {
attributes.put("inputEncoding", getInputEncoding());
}
if (attributes.get("outputEncoding") == null) {
attributes.put("outputEncoding", getOutputEncoding());
}
// Put any of the properties in directly into the Velocity context
for (Map.Entry<Object, Object> entry : project.getProperties().entrySet()) {
attributes.put((String) entry.getKey(), entry.getValue());
}
SiteRenderingContext context;
if (templateFile != null) {
getLog().info("Rendering site with " + templateFile + " template file.");
if (!templateFile.exists()) {
throw new MojoFailureException("Template file '" + templateFile + "' does not exist");
}
context = siteRenderer.createContextForTemplate(templateFile, attributes, decorationModel, project.getName(), locale);
} else {
try {
Artifact skinArtifact = siteTool.getSkinArtifactFromRepository(localRepository, repositories, decorationModel);
getLog().info("Rendering site with " + skinArtifact.getId() + " skin.");
context = siteRenderer.createContextForSkin(skinArtifact, attributes, decorationModel, project.getName(), locale);
} catch (SiteToolException e) {
throw new MojoExecutionException("SiteToolException while preparing skin: " + e.getMessage(), e);
} catch (RendererException e) {
throw new MojoExecutionException("RendererException while preparing context for skin: " + e.getMessage(), e);
}
}
// Generate static site
if (!locale.getLanguage().equals(Locale.getDefault().getLanguage())) {
context.addSiteDirectory(new File(siteDirectory, locale.getLanguage()));
context.addModuleDirectory(new File(xdocDirectory, locale.getLanguage()), "xdoc");
context.addModuleDirectory(new File(xdocDirectory, locale.getLanguage()), "fml");
} else {
context.addSiteDirectory(siteDirectory);
context.addModuleDirectory(xdocDirectory, "xdoc");
context.addModuleDirectory(xdocDirectory, "fml");
}
if (moduleExcludes != null) {
context.setModuleExcludes(moduleExcludes);
}
if (saveProcessedContent) {
context.setProcessedContentOutput(new File(generatedSiteDirectory, "processed"));
}
return context;
}
use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class WarMojo method performPackaging.
/**
* Generates the webapp according to the <tt>mode</tt> attribute.
*
* @param warFile the target WAR file
* @throws IOException if an error occurred while copying files
* @throws ArchiverException if the archive could not be created
* @throws ManifestException if the manifest could not be created
* @throws DependencyResolutionRequiredException if an error occurred while resolving the dependencies
* @throws MojoExecutionException if the execution failed
* @throws MojoFailureException if a fatal exception occurred
*/
private void performPackaging(File warFile) throws IOException, ManifestException, DependencyResolutionRequiredException, MojoExecutionException, MojoFailureException {
getLog().info("Packaging webapp");
buildExplodedWebapp(getWebappDirectory());
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(warArchiver);
archiver.setOutputFile(warFile);
// CHECKSTYLE_OFF: LineLength
getLog().debug("Excluding " + Arrays.asList(getPackagingExcludes()) + " from the generated webapp archive.");
getLog().debug("Including " + Arrays.asList(getPackagingIncludes()) + " in the generated webapp archive.");
// CHECKSTYLE_ON: LineLength
warArchiver.addDirectory(getWebappDirectory(), getPackagingIncludes(), getPackagingExcludes());
final File webXmlFile = new File(getWebappDirectory(), "WEB-INF/web.xml");
if (webXmlFile.exists()) {
warArchiver.setWebxml(webXmlFile);
}
warArchiver.setRecompressAddedZips(isRecompressZippedFiles());
warArchiver.setIncludeEmptyDirs(isIncludeEmptyDirectories());
if (Boolean.FALSE.equals(failOnMissingWebXml) || (failOnMissingWebXml == null && isProjectUsingAtLeastServlet30())) {
getLog().debug("Build won't fail if web.xml file is missing.");
warArchiver.setExpectWebXml(false);
}
// create archive
archiver.createArchive(getSession(), getProject(), getArchive());
// create the classes to be attached if necessary
if (isAttachClasses()) {
if (isArchiveClasses() && getJarArchiver().getDestFile() != null) {
// special handling in case of archived classes: MWAR-240
File targetClassesFile = getTargetClassesFile();
FileUtils.copyFile(getJarArchiver().getDestFile(), targetClassesFile);
projectHelper.attachArtifact(getProject(), "jar", getClassesClassifier(), targetClassesFile);
} else {
ClassesPackager packager = new ClassesPackager();
final File classesDirectory = packager.getClassesDirectory(getWebappDirectory());
if (classesDirectory.exists()) {
getLog().info("Packaging classes");
packager.packageClasses(classesDirectory, getTargetClassesFile(), getJarArchiver(), getSession(), getProject(), getArchive());
projectHelper.attachArtifact(getProject(), "jar", getClassesClassifier(), getTargetClassesFile());
}
}
}
if (this.classifier != null) {
projectHelper.attachArtifact(getProject(), "war", this.classifier, warFile);
} else {
Artifact artifact = getProject().getArtifact();
if (primaryArtifact) {
artifact.setFile(warFile);
} else if (artifact.getFile() == null || artifact.getFile().isDirectory()) {
artifact.setFile(warFile);
}
}
}
use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class ArtifactsPackagingTask method performPackaging.
/**
* {@inheritDoc}
*/
public void performPackaging(WarPackagingContext context) throws MojoExecutionException {
try {
final ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
final List<String> duplicates = findDuplicates(context, artifacts);
for (Artifact artifact : artifacts) {
String targetFileName = getArtifactFinalName(context, artifact);
context.getLog().debug("Processing: " + targetFileName);
if (duplicates.contains(targetFileName)) {
context.getLog().debug("Duplicate found: " + targetFileName);
targetFileName = artifact.getGroupId() + "-" + targetFileName;
context.getLog().debug("Renamed to: " + targetFileName);
}
context.getWebappStructure().registerTargetFileName(artifact, targetFileName);
if (!artifact.isOptional() && filter.include(artifact)) {
try {
String type = artifact.getType();
if ("tld".equals(type)) {
copyFile(id, context, artifact.getFile(), TLD_PATH + targetFileName);
} else if ("aar".equals(type)) {
copyFile(id, context, artifact.getFile(), SERVICES_PATH + targetFileName);
} else if ("mar".equals(type)) {
copyFile(id, context, artifact.getFile(), MODULES_PATH + targetFileName);
} else if ("xar".equals(type)) {
copyFile(id, context, artifact.getFile(), EXTENSIONS_PATH + targetFileName);
} else if ("jar".equals(type) || "ejb".equals(type) || "ejb-client".equals(type) || "test-jar".equals(type) || "bundle".equals(type)) {
copyFile(id, context, artifact.getFile(), LIB_PATH + targetFileName);
} else if ("par".equals(type)) {
targetFileName = targetFileName.substring(0, targetFileName.lastIndexOf('.')) + ".jar";
copyFile(id, context, artifact.getFile(), LIB_PATH + targetFileName);
} else if ("war".equals(type)) {
// Nothing to do here, it is an overlay and it's already handled
context.getLog().debug("war artifacts are handled as overlays, ignoring [" + artifact + "]");
} else if ("zip".equals(type)) {
// Nothing to do here, it is an overlay and it's already handled
context.getLog().debug("zip artifacts are handled as overlays, ignoring [" + artifact + "]");
} else {
context.getLog().debug("Artifact of type [" + type + "] is not supported, ignoring [" + artifact + "]");
}
} catch (IOException e) {
throw new MojoExecutionException("Failed to copy file for artifact [" + artifact + "]", e);
}
}
}
} catch (InterpolationException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class AntRunMojo method getPathFromArtifacts.
/**
* @param artifacts {@link Artifact} collection.
* @param antProject {@link Project}
* @return {@link Path}
* @throws DependencyResolutionRequiredException In case of a failure.
*
*/
public Path getPathFromArtifacts(Collection<Artifact> artifacts, Project antProject) throws DependencyResolutionRequiredException {
if (artifacts == null) {
return new Path(antProject);
}
List<String> list = new ArrayList<String>(artifacts.size());
for (Artifact a : artifacts) {
File file = a.getFile();
if (file == null) {
throw new DependencyResolutionRequiredException(a);
}
list.add(file.getPath());
}
Path p = new Path(antProject);
p.setPath(StringUtils.join(list.iterator(), File.pathSeparator));
return p;
}
use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class AntRunMojo method copyProperties.
/**
* Copy properties from the Maven project to the Ant project.
*
* @param mavenProject {@link MavenProject}
* @param antProject {@link Project}
*/
public void copyProperties(MavenProject mavenProject, Project antProject) {
Properties mavenProps = mavenProject.getProperties();
Properties userProps = session.getUserProperties();
for (String key : mavenProps.stringPropertyNames()) {
String value = userProps.getProperty(key, mavenProps.getProperty(key));
antProject.setProperty(key, value);
}
// Set the POM file as the ant.file for the tasks run directly in Maven.
antProject.setProperty("ant.file", mavenProject.getFile().getAbsolutePath());
// Add some of the common Maven properties
getLog().debug("Setting properties with prefix: " + propertyPrefix);
antProject.setProperty((propertyPrefix + "project.groupId"), mavenProject.getGroupId());
antProject.setProperty((propertyPrefix + "project.artifactId"), mavenProject.getArtifactId());
antProject.setProperty((propertyPrefix + "project.name"), mavenProject.getName());
if (mavenProject.getDescription() != null) {
antProject.setProperty((propertyPrefix + "project.description"), mavenProject.getDescription());
}
antProject.setProperty((propertyPrefix + "project.version"), mavenProject.getVersion());
antProject.setProperty((propertyPrefix + "project.packaging"), mavenProject.getPackaging());
antProject.setProperty((propertyPrefix + "project.build.directory"), mavenProject.getBuild().getDirectory());
antProject.setProperty((propertyPrefix + "project.build.outputDirectory"), mavenProject.getBuild().getOutputDirectory());
antProject.setProperty((propertyPrefix + "project.build.testOutputDirectory"), mavenProject.getBuild().getTestOutputDirectory());
antProject.setProperty((propertyPrefix + "project.build.sourceDirectory"), mavenProject.getBuild().getSourceDirectory());
antProject.setProperty((propertyPrefix + "project.build.testSourceDirectory"), mavenProject.getBuild().getTestSourceDirectory());
antProject.setProperty((propertyPrefix + "localRepository"), localRepository.toString());
antProject.setProperty((propertyPrefix + "settings.localRepository"), localRepository.getBasedir());
// Add properties for depenedency artifacts
Set<Artifact> depArtifacts = mavenProject.getArtifacts();
for (Artifact artifact : depArtifacts) {
String propName = artifact.getDependencyConflictId();
antProject.setProperty(propertyPrefix + propName, artifact.getFile().getPath());
}
// Add a property containing the list of versions for the mapper
StringBuilder versionsBuffer = new StringBuilder();
for (Artifact artifact : depArtifacts) {
versionsBuffer.append(artifact.getVersion()).append(File.pathSeparator);
}
antProject.setProperty(versionsPropertyName, versionsBuffer.toString());
}
Aggregations