Search in sources :

Example 1 with Plugin

use of org.apache.archiva.model.Plugin in project archiva by apache.

the class MavenRepositoryMetadataReaderTest method testGroupMetadata.

@Test
public void testGroupMetadata() throws XMLException {
    Path metadataFile = defaultRepoDir.resolve("org/apache/maven/plugins/maven-metadata.xml");
    ArchivaRepositoryMetadata metadata = MavenMetadataReader.read(metadataFile);
    assertNotNull(metadata);
    assertEquals("org.apache.maven.plugins", metadata.getGroupId());
    assertNull(metadata.getArtifactId());
    assertNull(metadata.getReleasedVersion());
    assertNull(metadata.getLatestVersion());
    assertTrue(metadata.getAvailableVersions().isEmpty());
    assertNull(metadata.getSnapshotVersion());
    assertNull(metadata.getLastUpdated());
    Plugin cleanPlugin = new Plugin();
    cleanPlugin.setPrefix("clean");
    cleanPlugin.setArtifactId("maven-clean-plugin");
    cleanPlugin.setName("Maven Clean Plugin");
    Plugin compilerPlugin = new Plugin();
    compilerPlugin.setPrefix("compiler");
    compilerPlugin.setArtifactId("maven-compiler-plugin");
    compilerPlugin.setName("Maven Compiler Plugin");
    Plugin surefirePlugin = new Plugin();
    surefirePlugin.setPrefix("surefire");
    surefirePlugin.setArtifactId("maven-surefire-plugin");
    surefirePlugin.setName("Maven Surefire Plugin");
    assertEquals(Arrays.asList(cleanPlugin, compilerPlugin, surefirePlugin), metadata.getPlugins());
}
Also used : Path(java.nio.file.Path) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) Plugin(org.apache.archiva.model.Plugin) Test(org.junit.Test)

Example 2 with Plugin

use of org.apache.archiva.model.Plugin in project archiva by apache.

the class MetadataTools method updateMetadata.

/**
 * Update the metadata to represent the all versions/plugins of
 * the provided groupId:artifactId project or group reference,
 * based off of information present in the repository,
 * the maven-metadata.xml files, and the proxy/repository specific
 * metadata file contents.
 * <p>
 * We must treat this as a group or a project metadata file as there is no way to know in advance
 *
 * @param managedRepository the managed repository where the metadata is kept.
 * @param reference         the reference to update.
 * @throws LayoutException
 * @throws RepositoryMetadataException
 * @throws IOException
 * @throws ContentNotFoundException
 * @deprecated
 */
public void updateMetadata(ManagedRepositoryContent managedRepository, ProjectReference reference) throws LayoutException, RepositoryMetadataException, IOException, ContentNotFoundException {
    Path metadataFile = Paths.get(managedRepository.getRepoRoot(), toPath(reference));
    long lastUpdated = getExistingLastUpdated(metadataFile);
    ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
    metadata.setGroupId(reference.getGroupId());
    metadata.setArtifactId(reference.getArtifactId());
    // Gather up all versions found in the managed repository.
    Set<String> allVersions = managedRepository.getVersions(reference);
    // Gather up all plugins found in the managed repository.
    // TODO: do we know this information instead?
    // Set<Plugin> allPlugins = managedRepository.getPlugins( reference );
    Set<Plugin> allPlugins;
    if (Files.exists(metadataFile)) {
        try {
            allPlugins = new LinkedHashSet<Plugin>(MavenMetadataReader.read(metadataFile).getPlugins());
        } catch (XMLException e) {
            throw new RepositoryMetadataException(e.getMessage(), e);
        }
    } else {
        allPlugins = new LinkedHashSet<Plugin>();
    }
    // Does this repository have a set of remote proxied repositories?
    Set<String> proxiedRepoIds = this.proxies.get(managedRepository.getId());
    if (CollectionUtils.isNotEmpty(proxiedRepoIds)) {
        // Add in the proxied repo version ids too.
        Iterator<String> it = proxiedRepoIds.iterator();
        while (it.hasNext()) {
            String proxyId = it.next();
            ArchivaRepositoryMetadata proxyMetadata = readProxyMetadata(managedRepository, reference, proxyId);
            if (proxyMetadata != null) {
                allVersions.addAll(proxyMetadata.getAvailableVersions());
                allPlugins.addAll(proxyMetadata.getPlugins());
                long proxyLastUpdated = getLastUpdated(proxyMetadata);
                lastUpdated = Math.max(lastUpdated, proxyLastUpdated);
            }
        }
    }
    if (!allVersions.isEmpty()) {
        updateMetadataVersions(allVersions, metadata);
    } else {
        // Add the plugins to the metadata model.
        metadata.setPlugins(new ArrayList<>(allPlugins));
        // artifact ID was actually the last part of the group
        metadata.setGroupId(metadata.getGroupId() + "." + metadata.getArtifactId());
        metadata.setArtifactId(null);
    }
    if (lastUpdated > 0) {
        metadata.setLastUpdatedTimestamp(toLastUpdatedDate(lastUpdated));
    }
    // Save the metadata model to disk.
    RepositoryMetadataWriter.write(metadata, metadataFile);
    ChecksummedFile checksum = new ChecksummedFile(metadataFile);
    checksum.fixChecksums(algorithms);
}
Also used : Path(java.nio.file.Path) ChecksummedFile(org.apache.archiva.checksum.ChecksummedFile) XMLException(org.apache.archiva.xml.XMLException) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) Plugin(org.apache.archiva.model.Plugin)

Example 3 with Plugin

use of org.apache.archiva.model.Plugin in project archiva by apache.

the class RepositoryMetadataMerge method clonePlugins.

/**
 * Clones a list of plugins.
 *
 * This method exists because ArchivaModelCloner.clonePlugins()
 * only works with artifact references.
 *
 * @param plugins
 * @return list of cloned plugins
 */
private static List<Plugin> clonePlugins(List<Plugin> plugins) {
    if (plugins == null) {
        return null;
    }
    List<Plugin> result = new ArrayList<>();
    for (Plugin plugin : plugins) {
        Plugin clonedPlugin = new Plugin();
        clonedPlugin.setArtifactId(plugin.getArtifactId());
        clonedPlugin.setName(plugin.getName());
        clonedPlugin.setPrefix(plugin.getPrefix());
        result.add(plugin);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Plugin(org.apache.archiva.model.Plugin)

Example 4 with Plugin

use of org.apache.archiva.model.Plugin in project archiva by apache.

the class RepositoryMetadataWriter method write.

public static void write(ArchivaRepositoryMetadata metadata, Writer writer) throws RepositoryMetadataException {
    Document doc = DocumentHelper.createDocument();
    Element root = DocumentHelper.createElement("metadata");
    doc.setRootElement(root);
    addOptionalElementText(root, "groupId", metadata.getGroupId());
    addOptionalElementText(root, "artifactId", metadata.getArtifactId());
    addOptionalElementText(root, "version", metadata.getVersion());
    if (CollectionUtils.isNotEmpty(metadata.getPlugins())) {
        Element plugins = root.addElement("plugins");
        List<Plugin> pluginList = metadata.getPlugins();
        Collections.sort(pluginList, PluginComparator.INSTANCE);
        for (Plugin plugin : metadata.getPlugins()) {
            Element p = plugins.addElement("plugin");
            p.addElement("prefix").setText(plugin.getPrefix());
            p.addElement("artifactId").setText(plugin.getArtifactId());
            addOptionalElementText(p, "name", plugin.getName());
        }
    }
    if (// 
    CollectionUtils.isNotEmpty(metadata.getAvailableVersions()) || // 
    StringUtils.isNotBlank(metadata.getReleasedVersion()) || // 
    StringUtils.isNotBlank(metadata.getLatestVersion()) || // 
    StringUtils.isNotBlank(metadata.getLastUpdated()) || (metadata.getSnapshotVersion() != null)) {
        Element versioning = root.addElement("versioning");
        addOptionalElementText(versioning, "latest", metadata.getLatestVersion());
        addOptionalElementText(versioning, "release", metadata.getReleasedVersion());
        if (metadata.getSnapshotVersion() != null) {
            Element snapshot = versioning.addElement("snapshot");
            String bnum = String.valueOf(metadata.getSnapshotVersion().getBuildNumber());
            addOptionalElementText(snapshot, "buildNumber", bnum);
            addOptionalElementText(snapshot, "timestamp", metadata.getSnapshotVersion().getTimestamp());
        }
        if (CollectionUtils.isNotEmpty(metadata.getAvailableVersions())) {
            Element versions = versioning.addElement("versions");
            Iterator<String> it = metadata.getAvailableVersions().iterator();
            while (it.hasNext()) {
                String version = it.next();
                versions.addElement("version").setText(version);
            }
        }
        addOptionalElementText(versioning, "lastUpdated", metadata.getLastUpdated());
    }
    try {
        XMLWriter.write(doc, writer);
    } catch (XMLException e) {
        throw new RepositoryMetadataException("Unable to write xml contents to writer: " + e.getMessage(), e);
    }
}
Also used : XMLException(org.apache.archiva.xml.XMLException) Element(org.dom4j.Element) Document(org.dom4j.Document) Plugin(org.apache.archiva.model.Plugin)

Example 5 with Plugin

use of org.apache.archiva.model.Plugin in project archiva by apache.

the class MetadataTransferTest method assertGroupMetadata.

private void assertGroupMetadata(Path actualFile, ProjectReference actualMetadata, String[] expectedPlugins) throws Exception {
    // Build expected metadata XML
    StringWriter expectedMetadataXml = new StringWriter();
    ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
    m.setGroupId(actualMetadata.getGroupId());
    for (String pluginId : expectedPlugins) {
        Plugin p = new Plugin();
        p.setPrefix(pluginId);
        p.setArtifactId(pluginId + "-maven-plugin");
        p.setName("The " + pluginId + " Plugin");
        m.getPlugins().add(p);
    }
    RepositoryMetadataWriter.write(m, expectedMetadataXml);
    // Compare the file to the actual contents.
    assertMetadataEquals(expectedMetadataXml.toString(), actualFile);
}
Also used : StringWriter(java.io.StringWriter) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) Plugin(org.apache.archiva.model.Plugin)

Aggregations

Plugin (org.apache.archiva.model.Plugin)6 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)4 Path (java.nio.file.Path)2 XMLException (org.apache.archiva.xml.XMLException)2 Element (org.dom4j.Element)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ChecksummedFile (org.apache.archiva.checksum.ChecksummedFile)1 SnapshotVersion (org.apache.archiva.model.SnapshotVersion)1 XMLReader (org.apache.archiva.xml.XMLReader)1 Document (org.dom4j.Document)1 Test (org.junit.Test)1