Search in sources :

Example 11 with DefaultRepositoryLayout

use of org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout in project tomee by apache.

the class AbstractTomEEMojo method resolve.

private File resolve() {
    if (!settings.isOffline()) {
        try {
            if ("snapshots".equals(apacheRepos) || "true".equals(apacheRepos)) {
                remoteRepos.add(new DefaultArtifactRepository("apache", "https://repository.apache.org/content/repositories/snapshots/", new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(true, UPDATE_POLICY_DAILY, CHECKSUM_POLICY_WARN), new ArtifactRepositoryPolicy(false, UPDATE_POLICY_NEVER, CHECKSUM_POLICY_WARN)));
            } else {
                try {
                    // to check it is a uri
                    new URI(apacheRepos);
                    remoteRepos.add(new DefaultArtifactRepository("additional-repo-tomee-mvn-plugin", apacheRepos, new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(true, UPDATE_POLICY_DAILY, CHECKSUM_POLICY_WARN), new ArtifactRepositoryPolicy(true, UPDATE_POLICY_NEVER, CHECKSUM_POLICY_WARN)));
                } catch (final URISyntaxException e) {
                // ignored, use classical repos
                }
            }
        } catch (final UnsupportedOperationException uoe) {
        // can happen if remoterepos is unmodifiable (possible in complex builds)
        // no-op
        }
    } else if (remoteRepos != null && remoteRepos.isEmpty()) {
        remoteRepos = new ArrayList<ArtifactRepository>();
    }
    if ((tomeeClassifier != null && (tomeeClassifier.isEmpty() || tomeeClassifier.equals("ignore"))) || ("org.apache.tomee".equals(tomeeGroupId) && "openejb-standalone".equals(tomeeArtifactId))) {
        tomeeClassifier = null;
    }
    try {
        final Artifact artifact = factory.createDependencyArtifact(tomeeGroupId, tomeeArtifactId, createFromVersion(tomeeVersion), tomeeType, tomeeClassifier, SCOPE_COMPILE);
        resolver.resolve(artifact, remoteRepos, local);
        return artifact.getFile();
    } catch (final Exception e) {
        getLog().error(e.getMessage(), e);
        throw new TomEEException(e.getMessage(), e);
    }
}
Also used : ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Artifact(org.apache.maven.artifact.Artifact) URISyntaxException(java.net.URISyntaxException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ScriptException(javax.script.ScriptException) OpenEJBException(org.apache.openejb.OpenEJBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchElementException(java.util.NoSuchElementException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 12 with DefaultRepositoryLayout

use of org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout in project tomee by apache.

the class TomEEMavenPluginRule method defaults.

protected static <T extends AbstractTomEEMojo> T defaults(final T tomEEMojo) {
    // settings
    final File settingsXml = new File(System.getProperty("user.home") + "/.m2/settings.xml");
    if (settingsXml.exists()) {
        try {
            final FileReader reader = new FileReader(settingsXml);
            try {
                tomEEMojo.settings = new SettingsXpp3Reader().read(reader, false);
            } finally {
                reader.close();
            }
        } catch (final Exception e) {
        // no-op
        }
    }
    tomEEMojo.project = new MavenProject() {

        @Override
        public Set getArtifacts() {
            return Collections.emptySet();
        }
    };
    if (tomEEMojo.settings == null) {
        tomEEMojo.settings = new Settings();
    }
    tomEEMojo.settings.setOffline(true);
    if (tomEEMojo.settings.getLocalRepository() == null || "".equals(tomEEMojo.settings.getLocalRepository())) {
        tomEEMojo.settings.setLocalRepository(System.getProperty("openejb.m2.home", System.getProperty("user.home") + "/.m2/repository"));
    }
    // we don't deploy anything by default
    tomEEMojo.skipCurrentProject = true;
    // our well known web profile ;)
    tomEEMojo.tomeeGroupId = "org.apache.tomee";
    tomEEMojo.tomeeArtifactId = "apache-tomee";
    tomEEMojo.tomeeVersion = OpenEjbVersion.get().getVersion();
    tomEEMojo.tomeeClassifier = "webprofile";
    tomEEMojo.tomeeType = "zip";
    // target config
    tomEEMojo.catalinaBase = new File("target/mvn-test");
    Files.mkdirs(tomEEMojo.catalinaBase);
    // some defaults
    tomEEMojo.simpleLog = true;
    tomEEMojo.quickSession = true;
    tomEEMojo.libDir = "lib";
    tomEEMojo.webappDir = "webapps";
    tomEEMojo.appDir = "apps";
    tomEEMojo.bin = new File(tomEEMojo.catalinaBase.getPath() + "-bin");
    tomEEMojo.config = new File(tomEEMojo.catalinaBase.getPath() + "-conf");
    tomEEMojo.lib = new File(tomEEMojo.catalinaBase.getPath() + "-lib");
    tomEEMojo.tomeeHttpPort = Integer.toString(NetworkUtil.getNextAvailablePort());
    tomEEMojo.tomeeAjpPort = Integer.toString(NetworkUtil.getNextAvailablePort());
    tomEEMojo.tomeeShutdownPort = Integer.toString(NetworkUtil.getNextAvailablePort());
    tomEEMojo.tomeeShutdownCommand = "SHUTDOWN";
    tomEEMojo.tomeeHost = "localhost";
    tomEEMojo.useConsole = true;
    tomEEMojo.checkStarted = true;
    tomEEMojo.overrideOnUnzip = true;
    tomEEMojo.skipRootFolderOnUnzip = true;
    // we mock all the artifact resolution in test
    tomEEMojo.remoteRepos = new LinkedList<ArtifactRepository>();
    tomEEMojo.local = new DefaultArtifactRepository("local", tomEEMojo.settings.getLocalRepository(), new DefaultRepositoryLayout());
    tomEEMojo.factory = ArtifactFactory.class.cast(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ArtifactFactory.class }, new InvocationHandler() {

        @Override
        public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
            return new DefaultArtifact(String.class.cast(args[0]), String.class.cast(args[1]), VersionRange.class.cast(args[2]), String.class.cast(args[5]), String.class.cast(args[3]), args[4] == null ? "" : String.class.cast(args[4]), null) {

                @Override
                public File getFile() {
                    return new File(tomEEMojo.settings.getLocalRepository(), getGroupId().replace('.', '/') + '/' + getArtifactId().replace('.', '/') + '/' + getVersion() + '/' + getArtifactId().replace('.', '/') + '-' + getVersion() + (args[4] == null ? "" : '-' + getClassifier()) + '.' + getType());
                }
            };
        }
    }));
    tomEEMojo.resolver = ArtifactResolver.class.cast(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ArtifactResolver.class }, new InvocationHandler() {

        @Override
        public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
            return null;
        }
    }));
    return tomEEMojo;
}
Also used : Set(java.util.Set) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) SettingsXpp3Reader(org.apache.maven.settings.io.xpp3.SettingsXpp3Reader) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) InvocationHandler(java.lang.reflect.InvocationHandler) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) MavenProject(org.apache.maven.project.MavenProject) FileReader(java.io.FileReader) File(java.io.File) Settings(org.apache.maven.settings.Settings) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 13 with DefaultRepositoryLayout

use of org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout in project cuke4duke by cucumber.

the class CucumberMojoTest method setUp.

@Before
public void setUp() {
    mojo = new CucumberMojo();
    mojo.launchDirectory = new File(".");
    mojo.mavenProject = new MavenProject();
    mojo.mavenProject.setFile(new File("../."));
    mojo.compileClasspathElements = new ArrayList<String>();
    mojo.pluginArtifacts = new ArrayList<Artifact>();
    mojo.testClasspathElements = new ArrayList<String>();
    mojo.localRepository = new DefaultArtifactRepository("", "", new DefaultRepositoryLayout());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) Before(org.junit.Before)

Aggregations

DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)13 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)10 File (java.io.File)9 URL (java.net.URL)6 HashSet (java.util.HashSet)6 Stack (java.util.Stack)5 Artifact (org.apache.maven.artifact.Artifact)5 TestInputHandler (org.apache.maven.plugins.repository.testutil.TestInputHandler)5 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)4 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)2 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)2 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)2 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 MavenProject (org.apache.maven.project.MavenProject)2 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1