Search in sources :

Example 21 with SimpleLocation

use of org.commonjava.maven.galley.model.SimpleLocation in project indy by Commonjava.

the class ContentControllerTest method detectHtml_MultipleHtmlElementsOnALine.

@Test
public void detectHtml_MultipleHtmlElementsOnALine() throws Exception {
    final ConcreteResource res = new ConcreteResource(new SimpleLocation("test:uri"), "file.html");
    final Transfer tx = fixture.getCache().getTransfer(res);
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(new OutputStreamWriter(tx.openOutputStream(TransferOperation.GENERATE)));
        writer.print("<html><body><h1>FOO</h1>");
        writer.flush();
    } finally {
        IOUtils.closeQuietly(writer);
    }
    assertThat(content.isHtmlContent(tx), equalTo(true));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 22 with SimpleLocation

use of org.commonjava.maven.galley.model.SimpleLocation in project indy by Commonjava.

the class ContentControllerTest method detectHtml_SingleHtmlElementLineWithPrecedingWhitespace.

@Test
public void detectHtml_SingleHtmlElementLineWithPrecedingWhitespace() throws Exception {
    final ConcreteResource res = new ConcreteResource(new SimpleLocation("test:uri"), "file.html");
    final Transfer tx = fixture.getCache().getTransfer(res);
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(new OutputStreamWriter(tx.openOutputStream(TransferOperation.GENERATE)));
        writer.print("    <html>");
        writer.flush();
    } finally {
        IOUtils.closeQuietly(writer);
    }
    assertThat(content.isHtmlContent(tx), equalTo(true));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 23 with SimpleLocation

use of org.commonjava.maven.galley.model.SimpleLocation in project galley by Commonjava.

the class AbstractMavenViewTest method loadPoms.

protected MavenPomView loadPoms(final String[] activeProfileIds, final String... pomNames) throws Exception {
    final List<DocRef<ProjectVersionRef>> stack = new ArrayList<DocRef<ProjectVersionRef>>();
    ProjectVersionRef pvr = null;
    for (final String pomName : pomNames) {
        final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(getBaseResource() + pomName);
        final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
        final ProjectVersionRef ref = xml.getProjectVersionRef(document);
        if (pvr == null) {
            pvr = ref;
        }
        final DocRef<ProjectVersionRef> dr = new DocRef<ProjectVersionRef>(ref, new SimpleLocation("http://localhost:8080/"), document);
        stack.add(dr);
    }
    return new MavenPomView(pvr, stack, xpath, new StandardMaven304PluginDefaults(), new StandardMavenPluginImplications(xml), xml, activeProfileIds);
}
Also used : StandardMaven304PluginDefaults(org.commonjava.maven.galley.maven.internal.defaults.StandardMaven304PluginDefaults) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Document(org.w3c.dom.Document) StandardMavenPluginImplications(org.commonjava.maven.galley.maven.internal.defaults.StandardMavenPluginImplications)

Example 24 with SimpleLocation

use of org.commonjava.maven.galley.model.SimpleLocation in project galley by Commonjava.

the class AbstractMavenViewTest method loadDocs.

protected MavenXmlView<ProjectRef> loadDocs(final Set<String> localOnlyPaths, final String... docNames) throws Exception {
    final List<DocRef<ProjectRef>> stack = new ArrayList<DocRef<ProjectRef>>();
    final ProjectRef pr = new SimpleProjectRef("not.used", "project-ref");
    for (final String pomName : docNames) {
        final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(getBaseResource() + pomName);
        final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
        final DocRef<ProjectRef> dr = new DocRef<ProjectRef>(pr, new SimpleLocation("http://localhost:8080/"), document);
        stack.add(dr);
    }
    return new MavenXmlView<ProjectRef>(stack, xpath, xml, localOnlyPaths.toArray(new String[localOnlyPaths.size()]));
}
Also used : SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) Document(org.w3c.dom.Document)

Example 25 with SimpleLocation

use of org.commonjava.maven.galley.model.SimpleLocation in project galley by Commonjava.

the class MavenModelProcessorTest method resolvePluginDependencyFromManagedInfo.

@Test
public void resolvePluginDependencyFromManagedInfo() throws Exception {
    final URI src = new URI("http://nowhere.com/path/to/repo");
    final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-child", "1.0");
    final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
    lineage.put(childRef, "child.pom.xml");
    lineage.put(new SimpleProjectVersionRef("org.test", "test-parent", "1.0"), "parent.pom.xml");
    final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true);
    final String base = PROJ_BASE + "dependency-in-managed-parent-plugin/";
    for (final Entry<ProjectVersionRef, String> entry : lineage.entrySet()) {
        final ProjectVersionRef ref = entry.getKey();
        final String filename = entry.getValue();
        final String path = ArtifactPathUtils.formatArtifactPath(ref.asPomArtifact(), fixture.getTypeMapper());
        fixture.getTransport().registerDownload(new ConcreteResource(location, path), new TestDownload(base + filename));
    }
    final Transfer transfer = fixture.getArtifactManager().retrieve(location, childRef.asPomArtifact());
    final MavenPomView pomView = fixture.getPomReader().read(childRef, transfer, Collections.singletonList(location));
    final List<PluginView> buildPlugins = pomView.getAllBuildPlugins();
    assertThat(buildPlugins, notNullValue());
    assertThat(buildPlugins.size(), equalTo(1));
    final PluginView pv = buildPlugins.get(0);
    assertThat(pv, notNullValue());
    final List<PluginDependencyView> deps = pv.getLocalPluginDependencies();
    assertThat(deps, notNullValue());
    assertThat(deps.size(), equalTo(1));
    final PluginDependencyView pdv = deps.get(0);
    assertThat(pdv, notNullValue());
    assertThat(pdv.asArtifactRef().getVersionString(), equalTo("1.0"));
    final ModelProcessorConfig discoveryConfig = new ModelProcessorConfig();
    discoveryConfig.setIncludeManagedDependencies(true);
    discoveryConfig.setIncludeBuildSection(true);
    discoveryConfig.setIncludeManagedPlugins(false);
    EProjectDirectRelationships result = fixture.getModelProcessor().readRelationships(pomView, src, discoveryConfig);
    final Set<ProjectRelationship<?, ?>> rels = result.getExactAllRelationships();
    logger.info("Found {} relationships:\n\n  {}", rels.size(), new JoinString("\n  ", rels));
    boolean seen = false;
    for (final ProjectRelationship<?, ?> rel : rels) {
        if (rel.getType() == RelationshipType.PLUGIN_DEP && !rel.isManaged()) {
            if (seen) {
                fail("Multiple plugin dependencies found!");
            }
            seen = true;
            assertThat(rel.getTarget().getVersionString(), equalTo("1.0"));
        }
    }
    if (!seen) {
        fail("Plugin-dependency relationship not found!");
    }
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ProjectRelationship(org.commonjava.maven.atlas.graph.rel.ProjectRelationship) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) PluginView(org.commonjava.maven.galley.maven.model.view.PluginView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Aggregations

SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)42 Test (org.junit.Test)39 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)35 Location (org.commonjava.maven.galley.model.Location)26 Transfer (org.commonjava.maven.galley.model.Transfer)22 InputStream (java.io.InputStream)12 OutputStream (java.io.OutputStream)10 CacheProvider (org.commonjava.maven.galley.spi.cache.CacheProvider)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)7 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)7 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)6 OutputStreamWriter (java.io.OutputStreamWriter)5 PrintWriter (java.io.PrintWriter)5 URI (java.net.URI)5 LinkedHashMap (java.util.LinkedHashMap)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)5 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)5 File (java.io.File)4