Example usage for org.apache.maven.artifact.handler ArtifactHandler getExtension

List of usage examples for org.apache.maven.artifact.handler ArtifactHandler getExtension

Introduction

In this page you can find the example usage for org.apache.maven.artifact.handler ArtifactHandler getExtension.

Prototype

String getExtension();

Source Link

Document

Get the file extension associated to the file represented by the dependency type.

Usage

From source file:com.rebaze.maven.support.AetherUtils.java

License:Open Source License

public static ArtifactType newArtifactType(String id, ArtifactHandler handler) {
    return new DefaultArtifactType(id, handler.getExtension(), handler.getClassifier(), handler.getLanguage(),
            handler.isAddedToClasspath(), handler.isIncludesDependencies());
}

From source file:com.redhat.tools.nexus.maven.plugin.buildhelper.InjectArtifactHandlerMojo.java

License:Open Source License

@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException {
    ArtifactVersion currentVersion = ri.getApplicationVersion();
    ArtifactVersion maxUsageVersion = new DefaultArtifactVersion("2.2.0");

    if (maxUsageVersion.compareTo(currentVersion) < 0) {
        getLog().debug(/*from   w  ww .j  a  v  a 2s . co  m*/
                "This version of Maven does not require injection of custom ArtifactHandlers using this code. Skipping.");
        return;
    }

    Map<String, ?> handlerDescriptors = session.getContainer().getComponentDescriptorMap(ArtifactHandler.ROLE);
    if (handlerDescriptors != null) {
        getLog().debug("Registering all unregistered ArtifactHandlers...");

        if (artifactHandlerManager instanceof DefaultArtifactHandlerManager) {
            Set<String> existingHints = ((DefaultArtifactHandlerManager) artifactHandlerManager)
                    .getHandlerTypes();
            if (existingHints != null) {
                for (String hint : existingHints) {
                    handlerDescriptors.remove(hint);
                }
            }
        }

        if (handlerDescriptors.isEmpty()) {
            getLog().debug("All ArtifactHandlers are registered. Continuing...");
        } else {
            Map<String, ArtifactHandler> unregisteredHandlers = new HashMap<String, ArtifactHandler>(
                    handlerDescriptors.size());

            for (String hint : handlerDescriptors.keySet()) {
                try {
                    unregisteredHandlers.put(hint,
                            (ArtifactHandler) session.lookup(ArtifactHandler.ROLE, hint));
                    getLog().info("Adding ArtifactHandler for: " + hint);
                } catch (ComponentLookupException e) {
                    getLog().warn("Failed to lookup ArtifactHandler with hint: " + hint + ". Reason: "
                            + e.getMessage(), e);
                }
            }

            artifactHandlerManager.addHandlers(unregisteredHandlers);
        }
    }

    getLog().debug("...done.\nSetting ArtifactHandler on project-artifact: " + project.getId() + "...");

    Set<Artifact> artifacts = new HashSet<Artifact>();
    artifacts.add(project.getArtifact());

    Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
    if (dependencyArtifacts != null && !dependencyArtifacts.isEmpty()) {
        artifacts.addAll(dependencyArtifacts);
    }

    for (Artifact artifact : artifacts) {
        String type = artifact.getType();
        ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(type);

        getLog().debug("Artifact: " + artifact.getId() + "\nType: " + type + "\nArtifactHandler extension: "
                + handler.getExtension());

        artifact.setArtifactHandler(handler);
    }

    getLog().debug("...done.");
}

From source file:hudson.gridmaven.reporters.MavenArtifact.java

License:Open Source License

/**
 * Creates a Maven {@link Artifact} back from the persisted data.
 *//*from  ww  w .  j a v a2  s .  c om*/
public Artifact toArtifact(ArtifactHandlerManager handlerManager, ArtifactFactory factory, MavenBuild build)
        throws IOException {
    // Hack: presence of custom ArtifactHandler during builds could influence the file extension
    // in the repository during deployment. So simulate that behavior if that's necessary.
    final String canonicalExtension = canonicalName.substring(canonicalName.lastIndexOf('.') + 1);
    ArtifactHandler ah = handlerManager.getArtifactHandler(type);
    Map<String, ArtifactHandler> handlers = Maps.newHashMap();

    handlers.put(type, new DefaultArtifactHandler(type) {
        public String getExtension() {
            return canonicalExtension;
        }
    });
    // Fix for HUDSON-3814 - changed from comparing against canonical extension to canonicalName.endsWith.
    if (!canonicalName.endsWith(ah.getExtension())) {
        handlerManager.addHandlers(handlers);
    }

    Artifact a = factory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
    a.setFile(getFile(build));

    return a;
}

From source file:org.apache.archiva.converter.artifact.LegacyRepositoryLayout.java

License:Apache License

@Override
public String pathOf(Artifact artifact) {
    ArtifactHandler artifactHandler = artifact.getArtifactHandler();

    StringBuilder path = new StringBuilder(128);

    path.append(artifact.getGroupId()).append('/');
    path.append(artifactHandler.getDirectory()).append('/');
    path.append(artifact.getArtifactId()).append('-').append(artifact.getVersion());

    if (artifact.hasClassifier()) {
        path.append('-').append(artifact.getClassifier());
    }//from w  w  w. ja v  a  2  s.  c om

    if (artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0) {
        path.append('.').append(artifactHandler.getExtension());
    }

    return path.toString();
}

From source file:org.apache.nifi.NarProvidedDependenciesMojo.java

License:Apache License

/**
 * Creates a new ArtifactHandler for the specified Artifact that overrides the includeDependencies flag. When set, this flag prevents transitive
 * dependencies from being printed in dependencies plugin.
 *
 * @param artifact  The artifact//from w w w  . j ava  2s.  co  m
 * @return          The handler for the artifact
 */
private ArtifactHandler excludesDependencies(final Artifact artifact) {
    final ArtifactHandler orig = artifact.getArtifactHandler();

    return new ArtifactHandler() {
        @Override
        public String getExtension() {
            return orig.getExtension();
        }

        @Override
        public String getDirectory() {
            return orig.getDirectory();
        }

        @Override
        public String getClassifier() {
            return orig.getClassifier();
        }

        @Override
        public String getPackaging() {
            return orig.getPackaging();
        }

        // mark dependencies has excluded so they will appear in tree listing
        @Override
        public boolean isIncludesDependencies() {
            return false;
        }

        @Override
        public String getLanguage() {
            return orig.getLanguage();
        }

        @Override
        public boolean isAddedToClasspath() {
            return orig.isAddedToClasspath();
        }
    };
}

From source file:org.apache.sling.maven.projectsupport.PrepareTestWebAppMojo.java

License:Apache License

private File getPrimaryArtifact() throws MojoExecutionException {
    ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(project.getPackaging());

    String artifactName = project.getBuild().getFinalName() + "." + handler.getExtension();

    File file = new File(buildDirectory, artifactName);
    if (!file.exists()) {
        throw new MojoExecutionException("Project's primary artifact (" + file.getPath() + ") doesn't exist.");
    }//from  ww  w .  jav a2  s  .  c  o m
    return file;
}

From source file:org.codehaus.mojo.appassembler.repository.FlatRepositoryLayout.java

License:Open Source License

public String pathOf(Artifact artifact) {
    ArtifactHandler artifactHandler = artifact.getArtifactHandler();

    StringBuffer path = new StringBuffer();

    path.append(artifact.getArtifactId()).append(ARTIFACT_SEPARATOR).append(artifact.getVersion());

    if (artifact.hasClassifier()) {
        path.append(ARTIFACT_SEPARATOR).append(artifact.getClassifier());
    }/*  ww w.java  2  s .c o m*/

    if (artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0) {
        path.append(GROUP_SEPARATOR).append(artifactHandler.getExtension());
    }

    return path.toString();
}

From source file:org.codehaus.mojo.appassembler.util.ArtifactUtils.java

License:Open Source License

/**
 * get relative path the copied artifact using base version. This is mainly use to SNAPSHOT instead of timestamp in
 * the file name/* w  ww .  ja v a2  s . c o  m*/
 * 
 * @param artifactRepositoryLayout
 * @param artifact
 * @return
 */
public static String pathBaseVersionOf(ArtifactRepositoryLayout artifactRepositoryLayout, Artifact artifact) {
    ArtifactHandler artifactHandler = artifact.getArtifactHandler();

    StringBuffer fileName = new StringBuffer();

    fileName.append(artifact.getArtifactId()).append("-").append(artifact.getBaseVersion());

    if (artifact.hasClassifier()) {
        fileName.append("-").append(artifact.getClassifier());
    }

    if (artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0) {
        fileName.append(".").append(artifactHandler.getExtension());
    }

    String relativePath = artifactRepositoryLayout.pathOf(artifact);
    String[] tokens = StringUtils.split(relativePath, "/");
    tokens[tokens.length - 1] = fileName.toString();

    StringBuffer path = new StringBuffer();

    for (int i = 0; i < tokens.length; ++i) {

        path.append(tokens[i]);
        if (i != tokens.length - 1) {
            path.append("/");
        }
    }

    return path.toString();

}

From source file:org.codehaus.mojo.jboss.packaging.AbstractPackagingMojo.java

License:Apache License

/**
 * Generates the packaged archive.//from   w  w w . ja v  a  2s . c  om
 * 
 * @throws MojoExecutionException if there is a problem
 */
protected void performPackaging() throws MojoExecutionException {

    ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(getArtifactType());
    String extension = artifactHandler.getExtension();
    String type = getArtifactType();

    final File archiveFile = calculateFile(outputDirectory, archiveName, classifier, extension);

    // generate archive file
    getLog().debug("Generating JBoss packaging " + archiveFile.getAbsolutePath());
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(archiveFile);
    try {
        jarArchiver.addDirectory(getPackagingDirectory());
        if (manifest != null) {
            jarArchiver.setManifest(manifest);
        }
        archiver.createArchive(getProject(), archive);
    } catch (Exception e) {
        throw new MojoExecutionException("Problem generating archive file.", e);
    }

    // If there is a classifier, then this archive is not the primary project artifact.
    if (classifier != null && !classifier.equals("")) {
        primaryArtifact = false;
    }

    if (primaryArtifact) {
        Artifact artifact = project.getArtifact();
        artifact.setFile(archiveFile);
        artifact.setArtifactHandler(artifactHandler);
    } else {
        projectHelper.attachArtifact(project, type, classifier, archiveFile);
    }
}

From source file:org.eclipse.che.maven.server.MavenModelUtil.java

License:Open Source License

private static String convertExtension(Artifact artifact) {
    ArtifactHandler artifactHandler = artifact.getArtifactHandler();
    String result = null;/*w ww  .j a  va  2  s. com*/

    if (artifactHandler != null) {
        result = artifactHandler.getExtension();
    }

    if (result == null) {
        result = artifact.getType();
    }
    return result;
}