Example usage for org.apache.maven.artifact.repository.layout ArtifactRepositoryLayout ROLE

List of usage examples for org.apache.maven.artifact.repository.layout ArtifactRepositoryLayout ROLE

Introduction

In this page you can find the example usage for org.apache.maven.artifact.repository.layout ArtifactRepositoryLayout ROLE.

Prototype

String ROLE

To view the source code for org.apache.maven.artifact.repository.layout ArtifactRepositoryLayout ROLE.

Click Source Link

Usage

From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.EclipseToMavenMojo.java

License:Open Source License

/**
 * Resolves the deploy<code>deployTo</code> parameter to an <code>ArtifactRepository</code> instance (if set).
 *
 * @return ArtifactRepository instance of null if <code>deployTo</code> is not set.
 * @throws MojoFailureException//from w w  w  . jav  a 2 s . c o  m
 * @throws MojoExecutionException
 */
private ArtifactRepository resolveRemoteRepo() throws MojoFailureException, MojoExecutionException {
    if (deployTo != null) {
        Matcher matcher = DEPLOYTO_PATTERN.matcher(deployTo);

        if (!matcher.matches()) {
            throw new MojoFailureException(deployTo,
                    Messages.getString("EclipseToMavenMojo.invalidsyntaxforrepository"),
                    //$NON-NLS-1$
                    Messages.getString("EclipseToMavenMojo.invalidremoterepositorysyntax")); //$NON-NLS-1$
        } else {
            String id = matcher.group(1).trim();
            String layout = matcher.group(2).trim();
            String url = matcher.group(3).trim();

            ArtifactRepositoryLayout repoLayout;
            try {
                repoLayout = (ArtifactRepositoryLayout) container.lookup(ArtifactRepositoryLayout.ROLE, layout);
            } catch (ComponentLookupException e) {
                throw new MojoExecutionException(
                        Messages.getString("EclipseToMavenMojo.cannotfindrepositorylayout", layout), e); //$NON-NLS-1$
            }

            return artifactRepositoryFactory.createDeploymentArtifactRepository(id, url, repoLayout, true);
        }
    }
    return null;
}

From source file:com.googlecode.jndiresources.maven.MavenEmbedder.java

License:Apache License

/**
 * Start the maven embedded./*from  w  ww  .j  a v a  2s  .  com*/
 * @throws DuplicateRealmException If error.
 * @throws PlexusContainerException If error.
 * @throws ComponentLookupException If error.
 * @throws IOException If error.
 * @throws XmlPullParserException If error.
 */
public void start() throws DuplicateRealmException, PlexusContainerException, ComponentLookupException,
        IOException, XmlPullParserException {
    detectUserInstallation();

    // ----------------------------------------------------------------------
    // Set the maven.home system property which is need by components like
    // the plugin registry builder.
    // ----------------------------------------------------------------------

    if (classLoader_ == null) {
        throw new IllegalStateException("A classloader must be specified using setClassLoader(ClassLoader).");
    }

    embedder_ = new Embedder();

    embedder_.setLoggerManager(new MavenEmbedderLoggerManager(new PlexusLogger()));

    final ClassWorld classWorld = new ClassWorld();

    classWorld.newRealm("plexus.core", classLoader_);

    embedder_.start(classWorld);

    // ----------------------------------------------------------------------
    // Artifact related components
    // ----------------------------------------------------------------------
    artifactRepositoryFactory_ = (ArtifactRepositoryFactory) embedder_.lookup(ArtifactRepositoryFactory.ROLE);

    artifactFactory_ = (ArtifactFactory) embedder_.lookup(ArtifactFactory.ROLE);

    artifactResolver_ = (ArtifactResolver) embedder_.lookup(ArtifactResolver.ROLE);

    defaultArtifactRepositoryLayout_ = (ArtifactRepositoryLayout) embedder_
            .lookup(ArtifactRepositoryLayout.ROLE, DEFAULT_LAYOUT_ID);

    // TODO : gestion Artifact
    // defaultMetadatSource=(ArtifactMetadataSource)embedder.lookup(ArtifactMetadataSource.ROLE);
    // defaultMetadatSource=new ArtifactRepositoryMetadata(artifact);
    createMavenSettings();
    localRepository_ = createLocalRepository(settings_);
}

From source file:com.webcohesion.enunciate.mojo.DeployArtifactBaseMojo.java

License:Apache License

private ArtifactRepository getDeploymentRepository() throws MojoExecutionException, MojoFailureException {
    if (deploymentRepository == null && altDeploymentRepository == null) {
        String msg = "Deployment failed: repository element was not specified in the pom inside"
                + " distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter";

        throw new MojoExecutionException(msg);
    }/*from   ww  w  .  j ava 2s  . c o  m*/

    ArtifactRepository repo = null;

    if (altDeploymentRepository != null) {
        getLog().info("Using alternate deployment repository " + altDeploymentRepository);

        Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher(altDeploymentRepository);

        if (!matcher.matches()) {
            throw new MojoFailureException(altDeploymentRepository, "Invalid syntax for repository.",
                    "Invalid syntax for alternative repository. Use \"id::layout::url\".");
        } else {
            String id = matcher.group(1).trim();
            String layout = matcher.group(2).trim();
            String url = matcher.group(3).trim();

            ArtifactRepositoryLayout repoLayout;
            try {
                repoLayout = (ArtifactRepositoryLayout) container.lookup(ArtifactRepositoryLayout.ROLE, layout);
            } catch (ComponentLookupException e) {
                throw new MojoExecutionException("Cannot find repository layout: " + layout, e);
            }

            repo = new DefaultArtifactRepository(id, url, repoLayout);
        }
    }

    if (repo == null) {
        repo = deploymentRepository;
    }

    return repo;
}

From source file:hudson.gridmaven.RedeployPublisher.java

License:Open Source License

public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
        throws InterruptedException, IOException {
    if (build.getResult().isWorseThan(getTreshold()))
        return true; // build failed. Don't publish

    /**//w ww  .  j a  v  a 2 s  . c o m
     * Check if we should skip or not
     */
    if (releaseEnvVar != null) {
        String envVarValue = build.getEnvironment(listener).get(releaseEnvVar);
        if ("true".equals(envVarValue)) { // null or false are ignored
            listener.getLogger().println("[INFO] Skipping deploying artifact as release build is in progress.");
            return true; // skip the deploy
        }
    }

    List<MavenAbstractArtifactRecord> mavenAbstractArtifactRecords = getActions(build, listener);
    if (mavenAbstractArtifactRecords == null || mavenAbstractArtifactRecords.isEmpty()) {
        listener.getLogger().println("[ERROR] No artifacts are recorded. Is this a Maven project?");
        build.setResult(Result.FAILURE);
        return true;
    }

    if (build instanceof MavenModuleSetBuild
            && ((MavenModuleSetBuild) build).getParent().isArchivingDisabled()) {
        listener.getLogger()
                .println("[ERROR] You cannot use the \"Deploy artifacts to Maven repository\" feature if you "
                        + "disabled automatic artifact archiving");
        build.setResult(Result.FAILURE);
        return true;
    }

    long startupTime = Calendar.getInstance().getTimeInMillis();

    try {
        MavenEmbedder embedder = createEmbedder(listener, build);
        ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) embedder
                .lookup(ArtifactRepositoryLayout.ROLE, "default");
        ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) embedder
                .lookup(ArtifactRepositoryFactory.ROLE);
        ArtifactRepository artifactRepository = null;
        if (url != null) {
            // By default we try to get the repository definition from the job configuration
            artifactRepository = getDeploymentRepository(factory, layout, id, url);
        }
        for (MavenAbstractArtifactRecord mavenAbstractArtifactRecord : mavenAbstractArtifactRecords) {
            if (artifactRepository == null && mavenAbstractArtifactRecord instanceof MavenArtifactRecord) {
                // If no repository definition is set on the job level we try to take it from the POM
                MavenArtifactRecord mavenArtifactRecord = (MavenArtifactRecord) mavenAbstractArtifactRecord;
                artifactRepository = getDeploymentRepository(factory, layout, mavenArtifactRecord.repositoryId,
                        mavenArtifactRecord.repositoryUrl);
            }
            if (artifactRepository == null) {
                listener.getLogger().println(
                        "[ERROR] No Repository settings defined in the job configuration or distributionManagement of the module.");
                build.setResult(Result.FAILURE);
                return true;
            }
            mavenAbstractArtifactRecord.deploy(embedder, artifactRepository, listener);
        }
        listener.getLogger().println("[INFO] Deployment done in "
                + Util.getTimeSpanString(Calendar.getInstance().getTimeInMillis() - startupTime));
        return true;
    } catch (MavenEmbedderException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    } catch (ComponentLookupException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    } catch (ArtifactDeploymentException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    }
    // failed
    build.setResult(Result.FAILURE);
    listener.getLogger().println("[INFO] Deployment failed after "
            + Util.getTimeSpanString(Calendar.getInstance().getTimeInMillis() - startupTime));
    return true;
}

From source file:hudson.maven.artifact.AbstractArtifactComponentTestCase.java

License:Apache License

protected ArtifactRepository localRepository() throws Exception {
    String path = "target/test-classes/repositories/" + component() + "/local-repository";

    File f = new File(getBasedir(), path);

    ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup(ArtifactRepositoryLayout.ROLE,
            "default");

    return new DefaultArtifactRepository("local", "file://" + f.getPath(), repoLayout);
}

From source file:hudson.maven.artifact.AbstractArtifactComponentTestCase.java

License:Apache License

protected ArtifactRepository remoteRepository() throws Exception {
    String path = "target/test-classes/repositories/" + component() + "/remote-repository";

    File f = new File(getBasedir(), path);

    ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup(ArtifactRepositoryLayout.ROLE,
            "default");

    ArtifactRepository repo = new DefaultArtifactRepository("test", "file://" + f.getPath(), repoLayout,
            new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy()) {
        {//w ww.  j a v a  2 s .com

        }

        @Override
        public boolean isUniqueVersion() {
            return false;
        }
    };

    return repo;
}

From source file:hudson.maven.artifact.AbstractArtifactComponentTestCase.java

License:Apache License

protected ArtifactRepository badRemoteRepository() throws Exception {
    ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup(ArtifactRepositoryLayout.ROLE,
            "default");

    return new DefaultArtifactRepository("test", "http://foo.bar/repository", repoLayout);
}

From source file:hudson.maven.RedeployPublisher.java

License:Open Source License

public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
        throws InterruptedException, IOException {
    if (build.getResult().isWorseThan(getTreshold()))
        return true; // build failed. Don't publish

    /**/*w ww  .  j  a v  a  2  s  .  co m*/
     * Check if we should skip or not
     */
    if (releaseEnvVar != null) {
        String envVarValue = build.getEnvironment(listener).get(releaseEnvVar);
        if ("true".equals(envVarValue)) { // null or false are ignored
            listener.getLogger().println("[INFO] Skipping deploying artifact as release build is in progress.");
            return true; // skip the deploy
        }
    }

    List<MavenAbstractArtifactRecord> mavenAbstractArtifactRecords = getActions(build, listener);
    if (mavenAbstractArtifactRecords == null || mavenAbstractArtifactRecords.isEmpty()) {
        listener.getLogger().println("[ERROR] No artifacts are recorded. Is this a Maven project?");
        build.setResult(Result.FAILURE);
        return true;
    }

    if (build instanceof MavenModuleSetBuild
            && ((MavenModuleSetBuild) build).getParent().isArchivingDisabled()) {
        listener.getLogger()
                .println("[ERROR] You cannot use the \"Deploy artifacts to Maven repository\" feature if you "
                        + "disabled automatic artifact archiving");
        build.setResult(Result.FAILURE);
        return true;
    }

    long startupTime = System.currentTimeMillis();

    try {
        MavenEmbedder embedder = createEmbedder(listener, build);
        ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) embedder
                .lookup(ArtifactRepositoryLayout.ROLE, "default");
        ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) embedder
                .lookup(ArtifactRepositoryFactory.ROLE);
        ArtifactRepository artifactRepository = null;
        if (url != null) {
            // By default we try to get the repository definition from the job configuration
            artifactRepository = getDeploymentRepository(factory, layout, id, url);
        }
        for (MavenAbstractArtifactRecord mavenAbstractArtifactRecord : mavenAbstractArtifactRecords) {
            if (artifactRepository == null && mavenAbstractArtifactRecord instanceof MavenArtifactRecord) {
                // If no repository definition is set on the job level we try to take it from the POM
                MavenArtifactRecord mavenArtifactRecord = (MavenArtifactRecord) mavenAbstractArtifactRecord;
                artifactRepository = getDeploymentRepository(factory, layout, mavenArtifactRecord.repositoryId,
                        mavenArtifactRecord.repositoryUrl);
            }
            if (artifactRepository == null) {
                listener.getLogger().println(
                        "[ERROR] No Repository settings defined in the job configuration or distributionManagement of the module.");
                build.setResult(Result.FAILURE);
                return true;
            }
            mavenAbstractArtifactRecord.deploy(embedder, artifactRepository, listener);
        }
        listener.getLogger().println("[INFO] Deployment done in "
                + Util.getTimeSpanString(System.currentTimeMillis() - startupTime));
        return true;
    } catch (MavenEmbedderException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    } catch (ComponentLookupException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    } catch (ArtifactDeploymentException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    }
    // failed
    build.setResult(Result.FAILURE);
    listener.getLogger().println("[INFO] Deployment failed after "
            + Util.getTimeSpanString(System.currentTimeMillis() - startupTime));
    return true;
}

From source file:net.sourceforge.vulcan.maven.integration.MavenIntegration.java

License:Open Source License

private ArtifactRepository createLocalRepository(Embedder embedder, Settings settings)
        throws ComponentLookupException {
    final ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) embedder
            .lookup(ArtifactRepositoryLayout.ROLE, "default");

    String url = settings.getLocalRepository();

    if (!url.startsWith("file:")) {
        url = "file://" + url;
    }/* w w w  .  j a  va 2 s .c  o m*/

    return new DefaultArtifactRepository("local", url, repositoryLayout);
}

From source file:org.apache.rat.mp.RatTestHelpers.java

License:Apache License

/**
 * Creates an instance of {@link ArtifactRepository}.
 *
 * @param container current plexus container.
 * @return A configured instance of {@link DefaultArtifactRepository}.
 * @throws Exception Creating the object failed.
 *///  w  w w  . j a  va 2  s  . com
public static ArtifactRepository newArtifactRepository(PlexusContainer container) throws Exception {
    File m2Dir = new File(System.getProperty("user.home"), ".m2");
    File settingsFile = new File(m2Dir, "settings.xml");
    String localRepo = null;
    if (settingsFile.exists()) {
        Settings settings = new SettingsXpp3Reader().read(new FileReader(settingsFile));
        localRepo = settings.getLocalRepository();
    }
    if (localRepo == null) {
        localRepo = System.getProperty("user.home") + "/.m2/repository";
    }
    ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) container
            .lookup(ArtifactRepositoryLayout.ROLE, "default");
    return new DefaultArtifactRepository("local", "file://" + localRepo, repositoryLayout);
}