Example usage for org.apache.maven.project MavenProject getArtifact

List of usage examples for org.apache.maven.project MavenProject getArtifact

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getArtifact.

Prototype

public Artifact getArtifact() 

Source Link

Usage

From source file:org.jfrog.build.extractor.maven.BuildInfoRecorder.java

License:Apache License

private void extractModuleArtifact(MavenProject project, Set<Artifact> artifacts) {
    Artifact artifact = project.getArtifact();
    if (artifact == null) {
        logger.warn("Skipping Artifactory Build-Info project artifact extraction: Null artifact.");
        return;/*from ww  w .  j a  v a 2s  .co  m*/
    }
    artifacts.add(artifact);
}

From source file:org.jfrog.build.extractor.maven.BuildInfoRecorder.java

License:Apache License

private void addArtifactsToCurrentModule(MavenProject project, ModuleBuilder module) {
    Set<Artifact> moduleArtifacts = currentModuleArtifacts.get();
    if (moduleArtifacts == null) {
        logger.warn(/*from   ww  w  .ja  va2 s .c o  m*/
                "Skipping Artifactory Build-Info module artifact addition: Null current module artifact list.");
        return;
    }

    ArtifactoryClientConfiguration.PublisherHandler publisher = conf.publisher;
    IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(),
            publisher.getExcludePatterns());
    boolean excludeArtifactsFromBuild = publisher.isFilterExcludedArtifactsFromBuild();

    boolean pomFileAdded = false;
    Artifact nonPomArtifact = null;
    String pomFileName = null;

    for (Artifact moduleArtifact : moduleArtifacts) {
        String artifactId = moduleArtifact.getArtifactId();
        String artifactVersion = moduleArtifact.getVersion();
        String artifactClassifier = moduleArtifact.getClassifier();
        String artifactExtension = moduleArtifact.getArtifactHandler().getExtension();
        String type = getTypeString(moduleArtifact.getType(), artifactClassifier, artifactExtension);

        String artifactName = getArtifactName(artifactId, artifactVersion, artifactClassifier,
                artifactExtension);

        ArtifactBuilder artifactBuilder = new ArtifactBuilder(artifactName).type(type);
        File artifactFile = moduleArtifact.getFile();

        if ("pom".equals(type)) {
            pomFileAdded = true;
            // For pom projects take the file from the project if the artifact file is null.
            if (moduleArtifact.equals(project.getArtifact())) {
                artifactFile = project.getFile(); // project.getFile() returns the project pom file
            }
        } else if (moduleArtifact.getMetadataList().size() > 0) {
            nonPomArtifact = moduleArtifact;
            pomFileName = StringUtils.removeEnd(artifactName, artifactExtension) + "pom";
        }

        org.jfrog.build.api.Artifact artifact = artifactBuilder.build();
        String groupId = moduleArtifact.getGroupId();
        String deploymentPath = getDeploymentPath(groupId, artifactId, artifactVersion, artifactClassifier,
                artifactExtension);
        // If excludeArtifactsFromBuild and the PatternMatcher found conflict, add the excluded artifact to the excluded artifact set.
        if (excludeArtifactsFromBuild && PatternMatcher.pathConflicts(deploymentPath, patterns)) {
            module.addExcludedArtifact(artifact);
        } else {
            module.addArtifact(artifact);
        }
        if (isPublishArtifacts(artifactFile)) {
            addDeployableArtifact(artifact, artifactFile, moduleArtifact.getGroupId(), artifactId,
                    artifactVersion, artifactClassifier, artifactExtension);
        }
    }
    /*
     * In case of non packaging Pom project module, we need to create the pom file from the ProjectArtifactMetadata on the Artifact
     */
    if (!pomFileAdded && nonPomArtifact != null) {
        String deploymentPath = getDeploymentPath(nonPomArtifact.getGroupId(), nonPomArtifact.getArtifactId(),
                nonPomArtifact.getVersion(), nonPomArtifact.getClassifier(), "pom");

        addPomArtifact(nonPomArtifact, module, patterns, deploymentPath, pomFileName,
                excludeArtifactsFromBuild);
    }
}

From source file:org.jfrog.jade.plugins.idea.AbstractIdeaMojo.java

License:Apache License

protected void doDependencyResolution() throws InvalidDependencyVersionException, ProjectBuildingException,
        InvalidVersionSpecificationException {
    // If the execution root project is not a parent (meaning it is last one in reactor list)
    // Then the mojo will inherit manually its configuration
    if (reactorProjects != null) {
        int nbProjects = reactorProjects.size();
        // Get the last project it contains the specific ideaj configuration
        if (nbProjects > 1) {
            MavenProject lastproject = reactorProjects.get(nbProjects - 1);
            if (lastproject.isExecutionRoot()) {
                //noinspection unchecked
                List<Plugin> plugins = lastproject.getBuildPlugins();
                fillPluginSettings(plugins, "jade-idea-plugin", this, null);
            }/*ww  w.  j  av  a2 s . c om*/
        }
    }

    MavenProject project = getExecutedProject();
    ArtifactRepository localRepo = getLocalRepository();
    Map managedVersions = createManagedVersionMap();

    try {
        ArtifactResolutionResult result = getArtifactResolver().resolveTransitively(getProjectArtifacts(),
                project.getArtifact(), managedVersions, localRepo, project.getRemoteArtifactRepositories(),
                artifactMetadataSource);

        project.setArtifacts(result.getArtifacts());
    } catch (ArtifactNotFoundException e) {
        getLog().debug(e.getMessage(), e);

        StringBuffer msg = new StringBuffer();
        msg.append("An error occurred during dependency resolution.\n\n");
        msg.append("    Failed to retrieve ").append(e.getDownloadUrl()).append("\n");
        msg.append("from the following repositories:");
        for (Iterator repositories = e.getRemoteRepositories().iterator(); repositories.hasNext();) {
            ArtifactRepository repository = (ArtifactRepository) repositories.next();
            msg.append("\n    ").append(repository.getId()).append("(").append(repository.getUrl()).append(")");
        }
        msg.append("\nCaused by: ").append(e.getMessage());

        getLog().warn(msg);
    } catch (ArtifactResolutionException e) {
        getLog().debug(e.getMessage(), e);

        StringBuffer msg = new StringBuffer();
        msg.append("An error occurred during dependency resolution of the following artifact:\n\n");
        msg.append("    ").append(e.getGroupId()).append(":").append(e.getArtifactId()).append(e.getVersion())
                .append("\n\n");
        msg.append("Caused by: ").append(e.getMessage());

        getLog().warn(msg);
    }
}

From source file:org.jfrog.jade.plugins.javac.JavacCompilerMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    Maven2AntManager mvnHelper = getMaven2AntManager();

    Project antProject = getAntProject();
    MavenProject project = getProject();

    Javac javac = new Javac();
    javac.setProject(antProject);//from  w  w w  .ja  v a2  s.  com

    Path src = javac.createSrc();
    mvnHelper.fillPathFromPaths(src, compileSourceRoots);

    Path sourcePath = javac.createSourcepath();
    mvnHelper.fillPathFromPaths(sourcePath, compileSourceRoots);

    if (sourceDependencies != null) {
        getLog().warn("");
        getLog().warn("***********************************************");
        getLog().warn("This module uses a non-standard compiler plugin");
        getLog().warn("which compiles external code for circular");
        getLog().warn("dependency workaround. The sourcesDependencies");
        getLog().warn("configuration should be removed as soon as possible");
        getLog().warn("***********************************************");
        getLog().warn("");

        mvnHelper.fillPathFromPaths(sourcePath, sourceDependencies);
    }

    if (packageName == null) {
        packageName = "";
    }
    getLog().debug("Package name: " + packageName);
    javac.createPatternSet().createInclude().setName(packageName.replace('.', '/') + "/**/*.java");

    if (includes != null) {
        for (String include : includes) {
            getLog().warn("Adding include pattern: " + include);
            javac.createPatternSet().createInclude().setName(include);
        }
    }

    if (excludes != null) {
        for (String exclude : excludes) {
            getLog().debug("Adding exclude pattern: " + exclude);
            javac.createPatternSet().createExclude().setName(exclude);
        }
    }

    mvnHelper.fillPathFromPaths(javac.createClasspath(), compileClasspathElements);

    File outputFileDir = new File(outputDirectory);
    if (!outputFileDir.exists()) {
        outputFileDir.mkdirs();
    }
    javac.setDestdir(outputFileDir);

    javac.setSource(source);
    javac.setTarget(target);
    javac.setOptimize(optimize);
    javac.setDebug(debug);
    javac.setDeprecation(showDeprecation);

    javac.setFork(fork);
    javac.setExecutable(executable);
    javac.setFailonerror(true);

    try {
        javac.execute();
    } catch (BuildException be) {
        throw new MojoExecutionException(be.getMessage(), be);
    }

    project.getArtifact().setFile(outputFileDir);
}

From source file:org.jfrog.jade.plugins.natives.plugin.NativeNameProvider.java

License:Apache License

public String getProjectName(MavenProject project) {
    Artifact artifact = project.getArtifact();
    boolean isLib = isLibrary(artifact);
    return getProjectName(project.getGroupId(), project.getArtifactId(), isLib);
}

From source file:org.jszip.maven.RunMojo.java

License:Apache License

private void injectMissingArtifacts(MavenProject destination, MavenProject source) {
    if (destination.getArtifact().getFile() == null && source.getArtifact().getFile() != null) {
        getLog().info("Pushing primary artifact from forked execution into current execution");
        destination.getArtifact().setFile(source.getArtifact().getFile());
    }//from   ww w .  j  a v a 2  s  .  co  m
    for (Artifact executedArtifact : source.getAttachedArtifacts()) {
        String executedArtifactId = (executedArtifact.getClassifier() == null ? "."
                : "-" + executedArtifact.getClassifier() + ".") + executedArtifact.getType();
        if (StringUtils.equals(executedArtifact.getGroupId(), destination.getGroupId())
                && StringUtils.equals(executedArtifact.getArtifactId(), destination.getArtifactId())
                && StringUtils.equals(executedArtifact.getVersion(), destination.getVersion())) {
            boolean found = false;
            for (Artifact artifact : destination.getAttachedArtifacts()) {
                if (StringUtils.equals(artifact.getGroupId(), destination.getGroupId())
                        && StringUtils.equals(artifact.getArtifactId(), destination.getArtifactId())
                        && StringUtils.equals(artifact.getVersion(), destination.getVersion())
                        && StringUtils.equals(artifact.getClassifier(), executedArtifact.getClassifier())
                        && StringUtils.equals(artifact.getType(), executedArtifact.getType())) {
                    if (artifact.getFile() == null) {
                        getLog().info("Pushing " + executedArtifactId
                                + " artifact from forked execution into current execution");
                        artifact.setFile(executedArtifact.getFile());
                    }
                    found = true;
                }
            }
            if (!found) {
                getLog().info("Attaching " + executedArtifactId
                        + " artifact from forked execution into current execution");
                projectHelper.attachArtifact(destination, executedArtifact.getType(),
                        executedArtifact.getClassifier(), executedArtifact.getFile());
            }
        }
    }
}

From source file:org.keedio.maven.plugins.shade.filter.MinijarFilter.java

License:Apache License

/**
 * @since 1.6//from   ww w . j a  v  a 2 s  .co  m
 */
@SuppressWarnings({ "unchecked" })
public MinijarFilter(MavenProject project, Log log, List<SimpleFilter> simpleFilters) throws IOException {

    this.log = log;

    Clazzpath cp = new Clazzpath();

    ClazzpathUnit artifactUnit = cp.addClazzpathUnit(new FileInputStream(project.getArtifact().getFile()),
            project.toString());

    for (Artifact dependency : project.getArtifacts()) {
        addDependencyToClasspath(cp, dependency);
    }

    removable = cp.getClazzes();
    removePackages(artifactUnit);
    removable.removeAll(artifactUnit.getClazzes());
    removable.removeAll(artifactUnit.getTransitiveDependencies());
    removeSpecificallyIncludedClasses(project,
            simpleFilters == null ? Collections.<SimpleFilter>emptyList() : simpleFilters);
}

From source file:org.m1theo.apt.repo.utils.Utils.java

License:Open Source License

/**
 * Collects all artifacts of the given type.
 * /*from   www.ja  v a 2 s .co m*/
 * @param project The maven project which should be used.
 * @param type The file type which should be collected.
 * @return A collection of all artifacts with the given type.
 */
@SuppressWarnings("unchecked")
public static Collection<Artifact> getAllArtifacts4Type(MavenProject project, String type, Boolean aggregate) {
    final Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
    List<MavenProject> modules = new ArrayList<MavenProject>();
    modules.add(project);
    List<MavenProject> collectedProjects = project.getCollectedProjects();
    if (collectedProjects != null) {
        modules.addAll(collectedProjects);
    }
    for (MavenProject module : modules) {
        addDebArtifact(module.getArtifact(), artifacts, type);
        for (Object artifact : module.getArtifacts()) {
            if (artifact instanceof Artifact) {
                addDebArtifact((Artifact) artifact, artifacts, type);
            }
        }
        for (Object artifact : module.getAttachedArtifacts()) {
            if (artifact instanceof Artifact) {
                addDebArtifact((Artifact) artifact, artifacts, type);
            }
        }
    }
    if (project.hasParent() && aggregate) {
        artifacts.addAll(getAllArtifacts4Type(project.getParent(), type, aggregate));
    }
    return artifacts;
}

From source file:org.maven.ide.eclipse.wtp.WebProjectConfiguratorDelegate.java

License:Open Source License

public void setModuleDependencies(IProject project, MavenProject mavenProject, IProgressMonitor monitor)
        throws CoreException {
    IVirtualComponent component = ComponentCore.createComponent(project);
    //if the attempt to create dependencies happens before the project is actually created, abort. 
    //this will be created again when the project exists.
    if (component == null) {
        return;/*ww w. j  av a 2s  . com*/
    }
    //MECLIPSEWTP-41 Fix the missing moduleCoreNature
    fixMissingModuleCoreNature(project, monitor);

    DebugUtilities.debug("==============Processing " + project.getName() + " dependencies ===============");
    WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project);
    IPackagingConfiguration opts = new PackagingConfiguration(config.getPackagingIncludes(),
            config.getPackagingExcludes());
    FileNameMapping fileNameMapping = config.getFileNameMapping();

    List<AbstractDependencyConfigurator> depConfigurators = ExtensionReader
            .readDependencyConfiguratorExtensions(projectManager,
                    MavenPlugin.getDefault().getMavenRuntimeManager(), mavenMarkerManager);

    Set<IVirtualReference> references = new LinkedHashSet<IVirtualReference>();
    List<IMavenProjectFacade> exportedDependencies = getWorkspaceDependencies(project, mavenProject);
    for (IMavenProjectFacade dependency : exportedDependencies) {
        String depPackaging = dependency.getPackaging();
        if ("pom".equals(depPackaging) //MNGECLIPSE-744 pom dependencies shouldn't be deployed
                || "war".equals(depPackaging) //Overlays are dealt with the overlay configurator
                || "zip".equals(depPackaging)) {
            continue;
        }

        try {
            preConfigureDependencyProject(dependency, monitor);

            if (!ModuleCoreNature.isFlexibleProject(dependency.getProject())) {
                //Projects unsupported by WTP (ex. adobe flex projects) should not be added as references
                continue;
            }
            MavenProject depMavenProject = dependency.getMavenProject(monitor);

            IVirtualComponent depComponent = ComponentCore.createComponent(dependency.getProject());

            ArtifactKey artifactKey = ArtifactHelper.toArtifactKey(depMavenProject.getArtifact());
            //Get artifact using the proper classifier
            Artifact artifact = ArtifactHelper.getArtifact(mavenProject.getArtifacts(), artifactKey);
            if (artifact == null) {
                //could not map key to artifact
                artifact = depMavenProject.getArtifact();
            }
            ArtifactHelper.fixArtifactHandler(artifact.getArtifactHandler());
            String deployedName = fileNameMapping.mapFileName(artifact);

            boolean isDeployed = !artifact.isOptional() && opts.isPackaged("WEB-INF/lib/" + deployedName);

            //an artifact in mavenProject.getArtifacts() doesn't have the "optional" value as depMavenProject.getArtifact();  
            if (isDeployed) {
                IVirtualReference reference = ComponentCore.createReference(component, depComponent);
                IPath path = new Path("/WEB-INF/lib");
                reference.setArchiveName(deployedName);
                reference.setRuntimePath(path);
                references.add(reference);
            }
        } catch (RuntimeException ex) {
            //Should probably be NPEs at this point
            String dump = DebugUtilities.dumpProjectState("An error occured while configuring a dependency of  "
                    + project.getName() + DebugUtilities.SEP, dependency.getProject());
            LOG.error(dump);
            throw ex;
        }
    }

    IVirtualReference[] oldRefs = WTPProjectsUtil.extractHardReferences(component, false);

    IVirtualReference[] newRefs = references.toArray(new IVirtualReference[references.size()]);

    if (WTPProjectsUtil.hasChanged(oldRefs, newRefs)) {
        //Only write in the .component file if necessary 
        IVirtualReference[] overlayRefs = WTPProjectsUtil.extractHardReferences(component, true);
        IVirtualReference[] allRefs = new IVirtualReference[overlayRefs.length + newRefs.length];
        System.arraycopy(newRefs, 0, allRefs, 0, newRefs.length);
        System.arraycopy(overlayRefs, 0, allRefs, newRefs.length, overlayRefs.length);
        component.setReferences(allRefs);
    }

    //TODO why a 2nd loop???
    for (IMavenProjectFacade dependency : exportedDependencies) {
        MavenProject depMavenProject = dependency.getMavenProject(monitor);
        Iterator<AbstractDependencyConfigurator> configurators = depConfigurators.iterator();
        while (configurators.hasNext()) {
            try {
                configurators.next().configureDependency(mavenProject, project, depMavenProject,
                        dependency.getProject(), monitor);
            } catch (MarkedException ex) {
                //XXX handle this
            }
        }
    }

}

From source file:org.mobicents.maven.plugin.eclipse.ClasspathWriter.java

License:Open Source License

/**
 * Writes the .classpath file for eclipse.
 * //from   w  ww  .ja  v a 2  s.  c  o  m
 * @param projects
 *            the list of projects from which the .classpath will get its
 *            dependencies.
 * @param repositoryVariableName
 *            the name of the maven repository variable.
 * @param artifactFactory
 *            the factory for constructing artifacts.
 * @param artifactResolver
 *            the artifact resolver.
 * @param localRepository
 *            the local repository instance.
 * @param artifactMetadataSource
 * @param classpathArtifactTypes
 *            the artifacts types that are allowed in the classpath file.
 * @param remoteRepositories
 *            the list of remote repository instances.
 * @param resolveTransitiveDependencies
 *            whether or not dependencies shall be transitively resolved.
 * @param merge
 *            anything extra (not auto-generated), that should be "merged"
 *            into the generated .classpath
 * @param classpathExcludes
 * @param includeTestsDirectory
 * @param includeResourcesDirectory
 * @throws Exception
 */
public void write(final List projects, final String repositoryVariableName,
        final ArtifactFactory artifactFactory, final ArtifactResolver artifactResolver,
        final ArtifactRepository localRepository, final ArtifactMetadataSource artifactMetadataSource,
        final Set classpathArtifactTypes, final List remoteRepositories,
        final boolean resolveTransitiveDependencies, final String merge, Set classpathExcludes,
        boolean includeResourcesDirectory) throws Exception {
    final String rootDirectory = PathNormalizer.normalizePath(this.project.getBasedir().toString());
    final File classpathFile = new File(rootDirectory, ".classpath");
    final FileWriter fileWriter = new FileWriter(classpathFile);
    final XMLWriter writer = new PrettyPrintXMLWriter(fileWriter, "UTF-8", null);
    writer.startElement("classpath");

    final Set projectArtifactIds = new LinkedHashSet();
    for (final Iterator iterator = projects.iterator(); iterator.hasNext();) {
        final MavenProject project = (MavenProject) iterator.next();
        final Artifact projectArtifact = artifactFactory.createArtifact(project.getGroupId(),
                project.getArtifactId(), project.getVersion(), null, project.getPackaging());
        projectArtifactIds.add(projectArtifact.getId());
    }

    // - collect the source roots for the root project (if they are any)
    Set<String> sourceRoots = collectSourceRoots(this.project, rootDirectory, writer,
            includeResourcesDirectory);

    final Set allArtifacts = new LinkedHashSet(this.project.createArtifacts(artifactFactory, null, null));

    for (final Iterator iterator = projects.iterator(); iterator.hasNext();) {
        final MavenProject project = (MavenProject) iterator.next();
        sourceRoots.addAll(collectSourceRoots(project, rootDirectory, writer, includeResourcesDirectory));
        final Set artifacts = project.createArtifacts(artifactFactory, null, null);
        // - get the direct dependencies
        for (final Iterator artifactIterator = artifacts.iterator(); artifactIterator.hasNext();) {
            final Artifact artifact = (Artifact) artifactIterator.next();
            // - don't attempt to resolve the artifact if its part of the
            // project (we
            // infer this if it has the same id has one of the projects or
            // is in
            // the same groupId).
            if (!projectArtifactIds.contains(artifact.getId())
                    && !project.getGroupId().equals(artifact.getGroupId())) {
                artifactResolver.resolve(artifact, project.getRemoteArtifactRepositories(), localRepository);
                allArtifacts.add(artifact);
            } else {
                allArtifacts.add(artifact);
            }
        }
    }

    // we have all source roots now, sort and write
    for (String sourceRoot : sourceRoots) {
        logger.info("Adding src path " + sourceRoot);
        this.writeClasspathEntry(writer, "src", sourceRoot);
    }

    // - remove the project artifacts
    for (final Iterator iterator = projects.iterator(); iterator.hasNext();) {
        final MavenProject project = (MavenProject) iterator.next();
        final Artifact projectArtifact = project.getArtifact();
        if (projectArtifact != null) {
            for (final Iterator artifactIterator = allArtifacts.iterator(); artifactIterator.hasNext();) {
                final Artifact artifact = (Artifact) artifactIterator.next();
                final String projectId = projectArtifact.getArtifactId();
                final String projectGroupId = projectArtifact.getGroupId();
                final String artifactId = artifact.getArtifactId();
                final String groupId = artifact.getGroupId();
                if (artifactId.equals(projectId) && groupId.equals(projectGroupId)) {
                    artifactIterator.remove();
                }
            }
        }
    }

    // - now we resolve transitively, if we have the flag on
    if (resolveTransitiveDependencies) {
        final Artifact rootProjectArtifact = artifactFactory.createArtifact(this.project.getGroupId(),
                this.project.getArtifactId(), this.project.getVersion(), null, this.project.getPackaging());

        final OrArtifactFilter filter = new OrArtifactFilter();
        filter.add(new ScopeArtifactFilter(Artifact.SCOPE_COMPILE));
        filter.add(new ScopeArtifactFilter(Artifact.SCOPE_PROVIDED));
        filter.add(new ScopeArtifactFilter(Artifact.SCOPE_TEST));
        final ArtifactResolutionResult result = artifactResolver.resolveTransitively(allArtifacts,
                rootProjectArtifact, localRepository, remoteRepositories, artifactMetadataSource, filter);

        allArtifacts.clear();
        allArtifacts.addAll(result.getArtifacts());
    }

    // remove excluded ones
    for (Iterator i = allArtifacts.iterator(); i.hasNext();) {
        Artifact artifact = (Artifact) i.next();

        if (classpathExcludes != null) {
            if (classpathExcludes.contains(artifact.getGroupId())) {
                logger.info("Excluding " + artifact + " from .classpath, groupId is excluded");
                i.remove();
            } else if (classpathExcludes.contains(artifact.getGroupId() + ":" + artifact.getArtifactId())) {
                logger.info("Excluding " + artifact + " from .classpath, groupId:artifactId is excluded");
                i.remove();
            } else if (classpathExcludes.contains(
                    artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion())) {
                logger.info(
                        "Excluding " + artifact + " from .classpath, groupId:artifactId:version is excluded");
                i.remove();
            }
        }
    }

    final List allArtifactPaths = new ArrayList(allArtifacts);
    for (final ListIterator iterator = allArtifactPaths.listIterator(); iterator.hasNext();) {
        final Artifact artifact = (Artifact) iterator.next();
        if (classpathArtifactTypes.contains(artifact.getType())) {
            File artifactFile = artifact.getFile();
            if (artifactFile == null) {
                artifactResolver.resolve(artifact, project.getRemoteArtifactRepositories(), localRepository);
                artifactFile = artifact.getFile();
            }
            if (artifactFile != null) {
                final String path = StringUtils.replace(PathNormalizer.normalizePath(artifactFile.toString()),
                        PathNormalizer.normalizePath(localRepository.getBasedir()), repositoryVariableName);
                iterator.set(path);
            } else {
                iterator.remove();
            }
        } else {
            iterator.remove();
        }
    }

    // - sort the paths
    Collections.sort(allArtifactPaths);

    for (final Iterator iterator = allArtifactPaths.iterator(); iterator.hasNext();) {
        String path = (String) iterator.next();
        if (path.startsWith(repositoryVariableName)) {
            this.writeClasspathEntry(writer, "var", path);
        } else {
            if (path.startsWith(rootDirectory)) {
                path = StringUtils.replace(path, rootDirectory + '/', "");
            }
            this.writeClasspathEntry(writer, "lib", path);
        }
    }

    this.writeClasspathEntry(writer, "con", "org.eclipse.jdt.launching.JRE_CONTAINER");

    String outputPath = StringUtils.replace(
            PathNormalizer.normalizePath(this.project.getBuild().getOutputDirectory()), rootDirectory, "");
    if (outputPath.startsWith("/")) {
        outputPath = outputPath.substring(1, outputPath.length());
    }
    this.writeClasspathEntry(writer, "output", outputPath);

    if (StringUtils.isNotBlank(merge)) {
        writer.writeMarkup(merge);
    }
    writer.endElement();

    logger.info("Classpath file written --> '" + classpathFile + "'");
    IOUtil.close(fileWriter);
}