summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHolger Oehm2011-09-01 12:15:09 (EDT)
committer jsievers2011-09-23 05:21:03 (EDT)
commit47ddd30ee48b9d39d0016724440aa5e2fd595d4e (patch)
tree81a713715d2e08853247db503b16162344153013
parent871a5cc4b6c8d68f8b06e2fcd08be707ac965095 (diff)
downloadorg.eclipse.tycho-47ddd30ee48b9d39d0016724440aa5e2fd595d4e.zip
org.eclipse.tycho-47ddd30ee48b9d39d0016724440aa5e2fd595d4e.tar.gz
org.eclipse.tycho-47ddd30ee48b9d39d0016724440aa5e2fd595d4e.tar.bz2
355367 Warn when locally built IUs are used in a build
- Determine which IUs have been resolved from the local repository and issues a warning about each of them. - While using locally built IUs is useful for certain use cases (incremental rebuilds, cross-project patches), it may yield unwanted results. The warning should help to identify the root cause in case this is a problem. Bug: 355367 Locally built artifacts override target plaftorm configuration
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/resolver/P2ResolverImpl.java1
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/resolver/ResolutionContextImpl.java14
-rw-r--r--tycho-its/src/test/java/org/eclipse/tycho/test/TYCHO0209tychoRepositoryRoundtrip/TychoRepositoryRoundtripTest.java2
-rw-r--r--tycho-p2-resolver/tycho-p2-resolver-impl/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/impl/resolver/ResolutionContextLocalRepositoryTest.java93
4 files changed, 109 insertions, 1 deletions
diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/resolver/P2ResolverImpl.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/resolver/P2ResolverImpl.java
index 97a3075..4e2c938 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/resolver/P2ResolverImpl.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/resolver/P2ResolverImpl.java
@@ -100,6 +100,7 @@ public class P2ResolverImpl implements P2Resolver {
strategy.setAdditionalRequirements(additionalRequirements);
Collection<IInstallableUnit> newState = strategy.resolve(monitor);
+ context.warnAboutLocalIus(newState);
context.downloadArtifacts(newState);
diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/resolver/ResolutionContextImpl.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/resolver/ResolutionContextImpl.java
index 100095f..7ef0e81 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/resolver/ResolutionContextImpl.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/resolver/ResolutionContextImpl.java
@@ -68,9 +68,9 @@ import org.eclipse.tycho.p2.maven.repository.MavenMirrorRequest;
import org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO;
import org.eclipse.tycho.p2.metadata.IArtifactFacade;
import org.eclipse.tycho.p2.metadata.IReactorArtifactFacade;
+import org.eclipse.tycho.p2.repository.FileBasedTychoRepositoryIndex;
import org.eclipse.tycho.p2.repository.GAV;
import org.eclipse.tycho.p2.repository.LocalRepositoryReader;
-import org.eclipse.tycho.p2.repository.FileBasedTychoRepositoryIndex;
import org.eclipse.tycho.p2.repository.RepositoryReader;
import org.eclipse.tycho.p2.repository.TychoRepositoryIndex;
import org.eclipse.tycho.p2.resolver.facade.ResolutionContext;
@@ -441,6 +441,18 @@ public class ResolutionContextImpl implements ResolutionContext {
return new QueryableArray(result.toArray(new IInstallableUnit[result.size()]));
}
+ public void warnAboutLocalIus(Collection<IInstallableUnit> ius) {
+ final Set<IInstallableUnit> locallyResolvedIUs = localMetadataRepository.query(QueryUtil.ALL_UNITS, null)
+ .toSet();
+ locallyResolvedIUs.retainAll(ius);
+ if (!locallyResolvedIUs.isEmpty()) {
+ logger.warn("The following locally built units have been used to resolve project dependencies:");
+ }
+ for (IInstallableUnit localIu : locallyResolvedIUs) {
+ logger.warn(" " + localIu.getId() + "/" + localIu.getVersion());
+ }
+ }
+
private static boolean isPartialIU(IInstallableUnit iu) {
return Boolean.valueOf(iu.getProperty(IInstallableUnit.PROP_PARTIAL_IU)).booleanValue();
}
diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/TYCHO0209tychoRepositoryRoundtrip/TychoRepositoryRoundtripTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/TYCHO0209tychoRepositoryRoundtrip/TychoRepositoryRoundtripTest.java
index b65fab6..4c9516a 100644
--- a/tycho-its/src/test/java/org/eclipse/tycho/test/TYCHO0209tychoRepositoryRoundtrip/TychoRepositoryRoundtripTest.java
+++ b/tycho-its/src/test/java/org/eclipse/tycho/test/TYCHO0209tychoRepositoryRoundtrip/TychoRepositoryRoundtripTest.java
@@ -33,6 +33,8 @@ public class TychoRepositoryRoundtripTest extends AbstractTychoIntegrationTest {
v02.getSystemProperties().setProperty("p2.repo", P2Repositories.ECLIPSE_342.toString());
v02.executeGoal("install");
v02.verifyErrorFreeLog();
+ v02.verifyTextInLog("[WARNING] The following locally built units have been used to resolve project dependencies:");
+ v02.verifyTextInLog("[WARNING] org.codehaus.tycho.tychoits.tycho0209.build01.bundle01/0.0.1.");
File site = new File(v02.getBasedir(), "build02.site01/target/site");
Assert.assertEquals(2, new File(site, "features").listFiles().length);
Assert.assertEquals(3, new File(site, "plugins").listFiles().length);
diff --git a/tycho-p2-resolver/tycho-p2-resolver-impl/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/impl/resolver/ResolutionContextLocalRepositoryTest.java b/tycho-p2-resolver/tycho-p2-resolver-impl/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/impl/resolver/ResolutionContextLocalRepositoryTest.java
new file mode 100644
index 0000000..3227c67
--- /dev/null
+++ b/tycho-p2-resolver/tycho-p2-resolver-impl/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/impl/resolver/ResolutionContextLocalRepositoryTest.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tycho.p2.impl.resolver;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.query.IQueryable;
+import org.eclipse.equinox.p2.query.QueryUtil;
+import org.eclipse.tycho.p2.impl.test.MavenLoggerStub;
+import org.eclipse.tycho.p2.maven.repository.LocalArtifactRepository;
+import org.eclipse.tycho.p2.maven.repository.LocalMetadataRepository;
+import org.eclipse.tycho.p2.repository.FileBasedTychoRepositoryIndex;
+import org.eclipse.tycho.p2.repository.GAV;
+import org.eclipse.tycho.p2.repository.LocalRepositoryReader;
+import org.eclipse.tycho.p2.repository.RepositoryReader;
+import org.eclipse.tycho.p2.repository.TychoRepositoryIndex;
+import org.eclipse.tycho.test.util.InstallableUnitUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ResolutionContextLocalRepositoryTest {
+
+ private static final NullProgressMonitor NULL_MONITOR = new NullProgressMonitor();
+ private MavenLoggerStub logger = new MavenLoggerStub();
+ private ResolutionContextImpl context;
+ private IInstallableUnit localIu;
+
+ @Before
+ public void setup() {
+ File localRepository = new File("target/localrepo");
+ IProvisioningAgent agent = P2ResolverFactoryImpl.getProvisioningAgent(localRepository, false);
+ P2RepositoryCache repositoryCache = (P2RepositoryCache) agent.getService(P2RepositoryCache.SERVICE_NAME);
+ URI uri = localRepository.toURI();
+ RepositoryReader contentLocator = new LocalRepositoryReader(localRepository);
+ TychoRepositoryIndex artifactsIndex = FileBasedTychoRepositoryIndex.createRepositoryIndex(localRepository,
+ FileBasedTychoRepositoryIndex.ARTIFACTS_INDEX_RELPATH);
+ TychoRepositoryIndex metadataIndex = FileBasedTychoRepositoryIndex.createRepositoryIndex(localRepository,
+ FileBasedTychoRepositoryIndex.METADATA_INDEX_RELPATH);
+ LocalArtifactRepository localArtifactRepository = new LocalArtifactRepository(localRepository, artifactsIndex,
+ contentLocator);
+ LocalMetadataRepository localMetadataRepository = new LocalMetadataRepository(uri, metadataIndex,
+ contentLocator);
+ repositoryCache.putRepository(uri, localMetadataRepository, localArtifactRepository);
+
+ context = new P2ResolverFactoryImpl().createResolutionContext(localRepository, false, false, logger);
+
+ localIu = InstallableUnitUtil.createIU("bundle", "1.0.0");
+ localMetadataRepository.addInstallableUnit(localIu, new GAV("group", "bundle", "1.0.0"));
+
+ final IQueryable<IInstallableUnit> ius = context.gatherAvailableInstallableUnits(NULL_MONITOR);
+ final Set<IInstallableUnit> resolvedIus = ius.query(QueryUtil.ALL_UNITS, NULL_MONITOR).toSet();
+ assertTrue(resolvedIus.contains(localIu));
+ }
+
+ @Test
+ public void testWarnAboutLocalIu() {
+ context.warnAboutLocalIus(Collections.singleton(localIu));
+ assertEquals(Arrays.asList("The following locally built units have been used to resolve project dependencies:",
+ " bundle/1.0.0"), logger.getWarnings());
+ }
+
+ @Test
+ public void testDontWarnAboutOtherIu() {
+ context.warnAboutLocalIus(Collections.singleton(InstallableUnitUtil.createIU("bundle", "1.0.1")));
+ assertTrue(logger.getWarnings().isEmpty());
+ }
+
+ @Test
+ public void testDontWarnAboutEmptySet() {
+ final Collection<IInstallableUnit> noIus = Collections.emptySet();
+ context.warnAboutLocalIus(noIus);
+ assertTrue(logger.getWarnings().isEmpty());
+ }
+}