forked from eclipse-tycho/tycho
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the repository format pluggable
Currently there needs to be a mojo for each format where the basics are quite common and just the serialization is special so it seems quite useful to reuse the basics.
- Loading branch information
Showing
7 changed files
with
368 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...ory-plugin/src/main/java/org/eclipse/tycho/repository/plugin/OSGiRepositoryGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Christoph Läubrich and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.repository.plugin; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.List; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.FilenameUtils; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugin.logging.Log; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.component.annotations.Component; | ||
import org.codehaus.plexus.configuration.PlexusConfiguration; | ||
import org.eclipse.tycho.MavenArtifactNamespace; | ||
import org.eclipse.tycho.packaging.RepositoryGenerator; | ||
|
||
import aQute.bnd.osgi.repository.XMLResourceGenerator; | ||
import aQute.bnd.osgi.resource.CapReqBuilder; | ||
import aQute.bnd.osgi.resource.ResourceBuilder; | ||
|
||
@Component(role = RepositoryGenerator.class, hint = OSGiRepositoryGenerator.HINT) | ||
public class OSGiRepositoryGenerator implements RepositoryGenerator { | ||
|
||
static final String HINT = "osgi"; | ||
|
||
@Override | ||
public File createRepository(List<MavenProject> projects, RepositoryConfiguration repoConfig) | ||
throws IOException, MojoExecutionException, MojoFailureException { | ||
XMLResourceGenerator resourceGenerator = new XMLResourceGenerator(); | ||
resourceGenerator.name(repoConfig.getRepositoryName()); | ||
File folder; | ||
PlexusConfiguration generatorConfig = repoConfig.getConfiguration(); | ||
String repositoryFileName = generatorConfig.getChild("repositoryFileName") | ||
.getValue("repository.xml"); | ||
if (repoConfig.getLayout() == RepositoryLayout.local) { | ||
String folderName = generatorConfig.getChild("repositoryFolderName") | ||
.getValue(FilenameUtils.getBaseName(repositoryFileName)); | ||
folder = new File(repoConfig.getDestination(), folderName); | ||
folder.mkdirs(); | ||
resourceGenerator.base(folder.toURI()); | ||
} else { | ||
folder = null; | ||
} | ||
Log log = repoConfig.getLog(); | ||
for (MavenProject project : projects) { | ||
ResourceBuilder rb = new ResourceBuilder(); | ||
try { | ||
URI uri; | ||
File file = project.getArtifact().getFile(); | ||
if (folder == null) { | ||
uri = new URI( | ||
"mvn:" + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion()); | ||
} else { | ||
uri = new File(folder, file.getName()).toURI(); | ||
} | ||
if (rb.addFile(project.getArtifact().getFile(), uri)) { | ||
CapReqBuilder identity = new CapReqBuilder(MavenArtifactNamespace.MAVEN_ARTIFACT_NAMESPACE) | ||
.addAttribute(MavenArtifactNamespace.CAPABILITY_GROUP_ATTRIBUTE, project.getGroupId()) | ||
.addAttribute(MavenArtifactNamespace.MAVEN_ARTIFACT_NAMESPACE, project.getArtifactId()) | ||
.addAttribute(MavenArtifactNamespace.CAPABILITY_VERSION_ATTRIBUTE, project.getVersion()); | ||
rb.addCapability(identity); | ||
resourceGenerator.resource(rb.build()); | ||
log.info("Adding " + project.getId()); | ||
if (folder != null) { | ||
FileUtils.copyFileToDirectory(file, folder); | ||
} | ||
} else { | ||
log.info("Skip " + project.getId() + ": Not a bundle"); | ||
} | ||
} catch (Exception e) { | ||
log.warn("Ignoring " + project.getId() + ": " + e, log.isDebugEnabled() ? e : null); | ||
} | ||
} | ||
if (folder != null) { | ||
File location = new File(folder, repositoryFileName); | ||
resourceGenerator.save(location); | ||
return folder; | ||
} else { | ||
File location = new File(repoConfig.getDestination(), repositoryFileName); | ||
resourceGenerator.save(location); | ||
return location; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
...repository-plugin/src/main/java/org/eclipse/tycho/repository/plugin/RepositoryLayout.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.