Skip to content

Commit

Permalink
Fix #592 - Move constants to shared bundle and then add p2 prefix there
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi committed Feb 2, 2022
1 parent a3cf563 commit 1f15e7e
Show file tree
Hide file tree
Showing 49 changed files with 277 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.eclipse.sisu.equinox.launching.EquinoxInstallationFactory;
import org.eclipse.tycho.ArtifactDescriptor;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.core.TychoConstants;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.core.osgitools.BundleReader;
import org.eclipse.tycho.core.osgitools.OsgiManifest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
import org.eclipse.sisu.equinox.EquinoxServiceFactory;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.ReactorProjectIdentities;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.core.DependencyResolver;
import org.eclipse.tycho.core.osgitools.DefaultReactorProject;
import org.eclipse.tycho.core.resolver.DefaultDependencyResolverFactory;
import org.eclipse.tycho.p2.repository.GAV;
import org.eclipse.tycho.p2.repository.RepositoryLayoutHelper;
import org.eclipse.tycho.p2.target.facade.PomDependencyCollector;
import org.eclipse.tycho.repository.registry.facade.ReactorRepositoryManagerFacade;

Expand Down Expand Up @@ -94,11 +94,11 @@ private void getTransitivelyReferencedTychoProjects(Collection<MavenProject> can
}

// check for target platform relevant build results (registered by either p2-metadata-default or attach-artifacts)
File metadataXml = getAttachedArtifact(reactorProject, RepositoryLayoutHelper.CLASSIFIER_P2_METADATA);
File metadataXml = getAttachedArtifact(reactorProject, TychoConstants.CLASSIFIER_P2_METADATA);
if (metadataXml == null) {
continue;
}
File artifactXml = getAttachedArtifact(reactorProject, RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS);
File artifactXml = getAttachedArtifact(reactorProject, TychoConstants.CLASSIFIER_P2_ARTIFACTS);

// found a Tycho project -> include in target platform
logger.debug("Adding reactor project: " + reactorProject.toString());
Expand Down Expand Up @@ -133,11 +133,11 @@ private static File getAttachedArtifact(MavenProject project, String classifier)

private static void verifyIndexFileLocations(ReactorProject project, File metadataXml, File artifactXml)
throws MojoExecutionException {
verifyArtifactLocationInTargetFolder(project, RepositoryLayoutHelper.CLASSIFIER_P2_METADATA,
RepositoryLayoutHelper.FILE_NAME_P2_METADATA, metadataXml);
verifyArtifactLocationInTargetFolder(project, RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS,
RepositoryLayoutHelper.FILE_NAME_P2_ARTIFACTS, artifactXml);
verifyFilePresenceInTargetFolder(project, RepositoryLayoutHelper.FILE_NAME_LOCAL_ARTIFACTS);
verifyArtifactLocationInTargetFolder(project, TychoConstants.CLASSIFIER_P2_METADATA,
TychoConstants.FILE_NAME_P2_METADATA, metadataXml);
verifyArtifactLocationInTargetFolder(project, TychoConstants.CLASSIFIER_P2_ARTIFACTS,
TychoConstants.FILE_NAME_P2_ARTIFACTS, artifactXml);
verifyFilePresenceInTargetFolder(project, TychoConstants.FILE_NAME_LOCAL_ARTIFACTS);
}

private static void verifyArtifactLocationInTargetFolder(ReactorProject project, String artifactClassifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
* Contributors:
* Sonatype Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.tycho.core;
package org.eclipse.tycho;

public interface TychoConstants {

static final String P2_GROUPID_PREFIX = "p2.";

static final String CONFIG_INI_PATH = "configuration/config.ini";
static final String BUNDLES_INFO_PATH = "configuration/org.eclipse.equinox.simpleconfigurator/bundles.info";
static final String PLATFORM_XML_PATH = "configuration/org.eclipse.update/platform.xml";
Expand All @@ -32,4 +35,59 @@ public interface TychoConstants {

static final String CTX_DEPENDENCY_WALKER = CTX_BASENAME + "/dependencyWalker";
static final String CTX_DEPENDENCY_SEEDS = CTX_BASENAME + "/dependencySeeds";

public String JAR_EXTENSION = "jar";

String PROP_GROUP_ID = "maven-groupId";

String PROP_ARTIFACT_ID = "maven-artifactId";

String PROP_VERSION = "maven-version";

String PROP_CLASSIFIER = "maven-classifier";

String PROP_REPOSITORY = "maven-repository";

String PROP_EXTENSION = "maven-extension";

String CLASSIFIER_P2_METADATA = "p2metadata";

String EXTENSION_P2_METADATA = "xml";

/**
* Name of the file where the module p2 metadata is stored in the target directory. The name
* needs to be known so that the target folder can be read as p2 metadata repository.
*/
String FILE_NAME_P2_METADATA = "p2content.xml";

String CLASSIFIER_P2_ARTIFACTS = "p2artifacts";

String EXTENSION_P2_ARTIFACTS = "xml";

/**
* Name of the file that contains the p2 artifact index. This file is one of the files needed to
* read the target folder as p2 artifact repository. The location is relative to the build
* target directory root.
*/
String FILE_NAME_P2_ARTIFACTS = "p2artifacts.xml";

/**
* Name of the file that stores the location of the Maven artifact in the target folder. This
* file is one of the files needed to read the target folder as p2 artifact repository.
*/
String FILE_NAME_LOCAL_ARTIFACTS = "local-artifacts.properties";

/**
* Key for the main artifact location in {@value FILE_NAME_LOCAL_ARTIFACTS} files.
*/
String KEY_ARTIFACT_MAIN = "artifact.main";

/**
* Key prefix for attached artifact locations in {@value FILE_NAME_LOCAL_ARTIFACTS} files.
*/
String KEY_ARTIFACT_ATTACHED = "artifact.attached.";

String PACK200_CLASSIFIER = "pack200";

String PACK200_EXTENSION = "jar.pack.gz";
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor;
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.core.shared.MavenLogger;
import org.eclipse.tycho.core.shared.MockMavenContext;
import org.eclipse.tycho.p2.repository.RepositoryLayoutHelper;
import org.eclipse.tycho.p2.repository.TychoRepositoryIndex;
import org.eclipse.tycho.repository.local.index.FileBasedTychoRepositoryIndex;
import org.eclipse.tycho.repository.local.testutil.TemporaryLocalMavenRepository;
Expand Down Expand Up @@ -123,9 +123,9 @@ private ArtifactDescriptor newBundleArtifactDescriptor(boolean maven) {
ArtifactDescriptor desc = new ArtifactDescriptor(key);

if (maven) {
desc.setProperty(RepositoryLayoutHelper.PROP_GROUP_ID, "group");
desc.setProperty(RepositoryLayoutHelper.PROP_ARTIFACT_ID, key.getId());
desc.setProperty(RepositoryLayoutHelper.PROP_VERSION, key.getVersion().toString());
desc.setProperty(TychoConstants.PROP_GROUP_ID, "group");
desc.setProperty(TychoConstants.PROP_ARTIFACT_ID, key.getId());
desc.setProperty(TychoConstants.PROP_VERSION, key.getVersion().toString());
}

return desc;
Expand Down Expand Up @@ -154,17 +154,17 @@ public void getMavenLocationWithClassifierAndExtension() {
"group/org.eclipse.tycho.test.maven/1.0.0/org.eclipse.tycho.test.maven-1.0.0.jar"),
repo.internalGetArtifactStorageLocation(desc));

desc.setProperty(RepositoryLayoutHelper.PROP_CLASSIFIER, "classifier.value");
desc.setProperty(TychoConstants.PROP_CLASSIFIER, "classifier.value");
assertEquals(new File(mvnRepo.getLocalRepositoryRoot(),
"group/org.eclipse.tycho.test.maven/1.0.0/org.eclipse.tycho.test.maven-1.0.0-classifier.value.jar"),
repo.internalGetArtifactStorageLocation(desc));

desc.setProperty(RepositoryLayoutHelper.PROP_EXTENSION, "zip");
desc.setProperty(TychoConstants.PROP_EXTENSION, "zip");
assertEquals(new File(mvnRepo.getLocalRepositoryRoot(),
"group/org.eclipse.tycho.test.maven/1.0.0/org.eclipse.tycho.test.maven-1.0.0-classifier.value.zip"),
repo.internalGetArtifactStorageLocation(desc));

desc.setProperty(RepositoryLayoutHelper.PROP_CLASSIFIER, null);
desc.setProperty(TychoConstants.PROP_CLASSIFIER, null);
assertEquals(
new File(mvnRepo.getLocalRepositoryRoot(),
"group/org.eclipse.tycho.test.maven/1.0.0/org.eclipse.tycho.test.maven-1.0.0.zip"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.core.shared.MavenLogger;
import org.eclipse.tycho.core.shared.MockMavenContext;
import org.eclipse.tycho.p2.repository.LocalRepositoryReader;
Expand Down Expand Up @@ -80,17 +81,17 @@ public void addInstallableUnit() throws CoreException {
iud.setId("test");
iud.setVersion(Version.parseVersion("1.0.0"));

iud.setProperty(RepositoryLayoutHelper.PROP_GROUP_ID, "group");
iud.setProperty(RepositoryLayoutHelper.PROP_ARTIFACT_ID, "artifact");
iud.setProperty(RepositoryLayoutHelper.PROP_VERSION, "version");
iud.setProperty(TychoConstants.PROP_GROUP_ID, "group");
iud.setProperty(TychoConstants.PROP_ARTIFACT_ID, "artifact");
iud.setProperty(TychoConstants.PROP_VERSION, "version");

InstallableUnitDescription iud2 = new MetadataFactory.InstallableUnitDescription();
iud2.setId("test2");
iud2.setVersion(Version.parseVersion("1.0.0"));

iud2.setProperty(RepositoryLayoutHelper.PROP_GROUP_ID, "group");
iud2.setProperty(RepositoryLayoutHelper.PROP_ARTIFACT_ID, "artifact2");
iud2.setProperty(RepositoryLayoutHelper.PROP_VERSION, "version");
iud2.setProperty(TychoConstants.PROP_GROUP_ID, "group");
iud2.setProperty(TychoConstants.PROP_ARTIFACT_ID, "artifact2");
iud2.setProperty(TychoConstants.PROP_VERSION, "version");

IInstallableUnit iu = MetadataFactory.createInstallableUnit(iud);
IInstallableUnit iu2 = MetadataFactory.createInstallableUnit(iud2);
Expand Down Expand Up @@ -118,9 +119,9 @@ public void testOutdatedIndex() throws CoreException {
InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
iud.setId("test");
iud.setVersion(Version.parseVersion("1.0.0"));
iud.setProperty(RepositoryLayoutHelper.PROP_GROUP_ID, "group");
iud.setProperty(RepositoryLayoutHelper.PROP_ARTIFACT_ID, "artifact");
iud.setProperty(RepositoryLayoutHelper.PROP_VERSION, "version");
iud.setProperty(TychoConstants.PROP_GROUP_ID, "group");
iud.setProperty(TychoConstants.PROP_ARTIFACT_ID, "artifact");
iud.setProperty(TychoConstants.PROP_VERSION, "version");
IInstallableUnit iu = MetadataFactory.createInstallableUnit(iud);
repository.addInstallableUnits(Arrays.asList(iu));
repository = (LocalMetadataRepository) loadRepository(location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.tycho.p2.repository.RepositoryLayoutHelper;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.repository.publishing.PublishingRepository;
import org.eclipse.tycho.repository.publishing.WriteSessionContext;
import org.eclipse.tycho.repository.publishing.WriteSessionContext.ClassifierAndExtension;
Expand Down Expand Up @@ -107,10 +107,10 @@ public void testArtifactDescriptor() throws Exception {
IArtifactDescriptor[] descriptors = artifactRepo.getArtifactDescriptors(AttachedTestArtifact.key);
assertThat(descriptors.length, is(1));
Map<String, String> props = descriptors[0].getProperties();
assertThat(props.get(RepositoryLayoutHelper.PROP_GROUP_ID), is(project.getGroupId()));
assertThat(props.get(RepositoryLayoutHelper.PROP_ARTIFACT_ID), is(project.getArtifactId()));
assertThat(props.get(RepositoryLayoutHelper.PROP_VERSION), is(project.getVersion()));
assertThat(props.get(RepositoryLayoutHelper.PROP_CLASSIFIER), is(AttachedTestArtifact.classifier));
assertThat(props.get(TychoConstants.PROP_GROUP_ID), is(project.getGroupId()));
assertThat(props.get(TychoConstants.PROP_ARTIFACT_ID), is(project.getArtifactId()));
assertThat(props.get(TychoConstants.PROP_VERSION), is(project.getVersion()));
assertThat(props.get(TychoConstants.PROP_CLASSIFIER), is(AttachedTestArtifact.classifier));
}

private static void insertTestArtifact(PublishingRepository publishingRepo) throws ProvisionException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import org.eclipse.equinox.p2.repository.IRepositoryReference;
import org.eclipse.equinox.p2.repository.metadata.spi.AbstractMetadataRepository;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO;
import org.eclipse.tycho.p2.repository.GAV;
import org.eclipse.tycho.p2.repository.RepositoryLayoutHelper;
import org.eclipse.tycho.p2.repository.RepositoryReader;
import org.eclipse.tycho.p2.repository.TychoRepositoryIndex;

Expand Down Expand Up @@ -73,7 +73,7 @@ protected void load() {
for (GAV gav : metadataIndex.getProjectGAVs()) {
try {
File localArtifactFileLocation = contentLocator.getLocalArtifactLocation(gav,
RepositoryLayoutHelper.CLASSIFIER_P2_METADATA, ArtifactType.TYPE_P2_METADATA);
TychoConstants.CLASSIFIER_P2_METADATA, ArtifactType.TYPE_P2_METADATA);
if (!localArtifactFileLocation.exists()) {
// if files have been manually removed from the repository, simply remove them from the index (bug 351080)
metadataIndex.removeGav(gav);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.p2.repository.GAV;
import org.eclipse.tycho.p2.repository.MavenRepositoryCoordinates;
import org.eclipse.tycho.p2.repository.RepositoryLayoutHelper;
Expand Down Expand Up @@ -78,8 +79,8 @@ private static MavenRepositoryCoordinates getP2DerivedCoordinates(IArtifactKey k

if (properties != null
&& IArtifactDescriptor.FORMAT_PACKED.equals(properties.get(IArtifactDescriptor.FORMAT))) {
classifier = RepositoryLayoutHelper.PACK200_CLASSIFIER;
extension = RepositoryLayoutHelper.PACK200_EXTENSION;
classifier = TychoConstants.PACK200_CLASSIFIER;
extension = TychoConstants.PACK200_EXTENSION;
}

return new MavenRepositoryCoordinates(gav, classifier, extension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.p2.maven.repository.Activator;
import org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO;
import org.eclipse.tycho.p2.repository.GAV;
Expand Down Expand Up @@ -78,13 +79,13 @@ private void loadMaven() {
for (final GAV gav : index.getProjectGAVs()) {
try {
File localArtifactFileLocation = contentLocator.getLocalArtifactLocation(gav,
RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS, ArtifactType.TYPE_P2_ARTIFACTS);
TychoConstants.CLASSIFIER_P2_ARTIFACTS, ArtifactType.TYPE_P2_ARTIFACTS);
if (!localArtifactFileLocation.exists()) {
// if files have been manually removed from the repository, simply remove them from the index (bug 351080)
index.removeGav(gav);
} else {
try (InputStream is = new FileInputStream(contentLocator.getLocalArtifactLocation(gav,
RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS, ArtifactType.TYPE_P2_ARTIFACTS))) {
TychoConstants.CLASSIFIER_P2_ARTIFACTS, ArtifactType.TYPE_P2_ARTIFACTS))) {
final Set<IArtifactDescriptor> gavDescriptors = io.readXML(is);
for (IArtifactDescriptor descriptor : gavDescriptors) {
internalAddDescriptor(descriptor);
Expand Down Expand Up @@ -147,7 +148,7 @@ private synchronized void saveMaven() {
}

private String getMetadataRelpath(GAV gav) {
String relpath = RepositoryLayoutHelper.getRelativePath(gav, RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS,
String relpath = RepositoryLayoutHelper.getRelativePath(gav, TychoConstants.CLASSIFIER_P2_ARTIFACTS,
ArtifactType.TYPE_P2_ARTIFACTS, localRepoIndices.getMavenContext());
return relpath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.core.shared.MavenContext;
import org.eclipse.tycho.p2.maven.repository.AbstractMavenMetadataRepository;
import org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO;
Expand Down Expand Up @@ -93,7 +94,7 @@ public void save() {
mavenContext = metadataIndex.getMavenContext();
}
String relpath = RepositoryLayoutHelper.getRelativePath(gav,
RepositoryLayoutHelper.CLASSIFIER_P2_METADATA, ArtifactType.TYPE_P2_METADATA, mavenContext);
TychoConstants.CLASSIFIER_P2_METADATA, ArtifactType.TYPE_P2_METADATA, mavenContext);

File file = new File(basedir, relpath);
file.getParentFile().mkdirs();
Expand Down
Loading

0 comments on commit 1f15e7e

Please sign in to comment.