Search in sources :

Example 1 with SettingsXpp3Reader

use of org.apache.maven.settings.io.xpp3.SettingsXpp3Reader in project indy by Commonjava.

the class SettingsGeneratedForRemoteRepoTest method generateSettingsXml.

@Test
public void generateSettingsXml() throws Exception {
    final IndyClientHttp http = getHttp();
    // all mavdav requests are siblings of the default base-url suffix '/api/'
    final String url = getDotMavenUrl("settings/remote/settings-central.xml");
    System.out.println("Requesting: " + url);
    final HttpResources resources = http.getRaw(new HttpGet(url));
    InputStream stream = null;
    Settings settings = null;
    try {
        stream = resources.getResponseStream();
        settings = new SettingsXpp3Reader().read(stream);
    } finally {
        closeQuietly(stream);
        closeQuietly(resources);
    }
    assertThat(settings.getLocalRepository(), equalTo("${user.home}/.m2/repo-remote-central"));
    assertThat(settings.getMirrors(), notNullValue());
    assertThat(settings.getMirrors().size(), equalTo(1));
    final Mirror mirror = settings.getMirrors().get(0);
    assertThat(mirror.getUrl(), equalTo(http.toIndyUrl("remote/central")));
}
Also used : InputStream(java.io.InputStream) IndyClientHttp(org.commonjava.indy.client.core.IndyClientHttp) HttpResources(org.commonjava.indy.client.core.helper.HttpResources) HttpGet(org.apache.http.client.methods.HttpGet) SettingsXpp3Reader(org.apache.maven.settings.io.xpp3.SettingsXpp3Reader) Mirror(org.apache.maven.settings.Mirror) Settings(org.apache.maven.settings.Settings) Test(org.junit.Test)

Example 2 with SettingsXpp3Reader

use of org.apache.maven.settings.io.xpp3.SettingsXpp3Reader 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)

Aggregations

Settings (org.apache.maven.settings.Settings)2 SettingsXpp3Reader (org.apache.maven.settings.io.xpp3.SettingsXpp3Reader)2 File (java.io.File)1 FileReader (java.io.FileReader)1 InputStream (java.io.InputStream)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 Set (java.util.Set)1 HttpGet (org.apache.http.client.methods.HttpGet)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)1 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)1 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)1 MavenProject (org.apache.maven.project.MavenProject)1 Mirror (org.apache.maven.settings.Mirror)1 IndyClientHttp (org.commonjava.indy.client.core.IndyClientHttp)1 HttpResources (org.commonjava.indy.client.core.helper.HttpResources)1 Test (org.junit.Test)1