Skip to content

Commit

Permalink
Improve the aggregator's maven publishing to support resolving package
Browse files Browse the repository at this point in the history
requirements

#11
  • Loading branch information
merks committed Jul 11, 2022
1 parent 6ce5691 commit 73de27b
Show file tree
Hide file tree
Showing 48 changed files with 5,035 additions and 486 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ Require-Bundle: org.apache.batik.awt.util,
org.eclipse.jdt.ui,
org.eclipse.jface.text,
org.eclipse.gmf.runtime.draw2d.ui.render.awt,
org.eclipse.cbi.p2repo.aggregator.edit;visibility:=reexport,
org.eclipse.cbi.p2repo.aggregator.analyzer.edit;visibility:=reexport,
org.eclipse.cbi.p2repo.aggregator.edit;visibility:=reexport,
org.eclipse.cbi.p2repo.aggregator.engine.maven,
org.eclipse.cbi.p2repo.p2.edit;visibility:=reexport,
org.eclipse.cbi.p2repo.p2.maven,
org.eclipse.cbi.p2repo.aggregator.engine,
org.eclipse.cbi.p2repo.util,
org.eclipse.m2e.maven.runtime,
org.eclipse.ui,
org.eclipse.ui.ide;visibility:=reexport,
org.eclipse.zest.core,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ public abstract class BaseHandler extends AbstractHandler {
protected static Path CACHE = Path
.of(AggregationAnalyzerEditorPlugin.getPlugin().getStateLocation().append("cache").toOSString());

protected static Path getCachePath(URI uri) throws IOException {
protected static Path getCachePath(URI uri) {
String decodedURI = URI.decode(uri.toString());
String[] uriSegments = decodedURI.split("[:/?#&;]+");
Path result = CACHE.resolve(String.join("/", uriSegments));
if (uri.hasTrailingPathSeparator()) {
return result.resolve("-folder-contents");
}
return result;
}

Expand All @@ -85,6 +88,36 @@ protected static String getContent(URI uri) throws IOException {
}
}

protected static String getContentOrEmpty(URI uri) {
Path path = getCachePath(uri);
if (Files.isRegularFile(path)) {
try {
return Files.readString(path);
} catch (IOException e) {
return "";
}
}

try {
Files.createDirectories(path.getParent());
} catch (IOException e) {
throw new RuntimeException(e);
}

try (InputStream in = URIConverter.INSTANCE.createInputStream(uri)) {
String content = new String(in.readAllBytes(), StandardCharsets.UTF_8);
Files.writeString(path, content);
return content;
} catch (IOException e) {
try {
Files.writeString(path, "");
} catch (IOException e1) {
//$FALL-THROUGH$
}
return "";
}
}

protected static Long getLastModified(URI logURI, Pattern datePattern, String dateFormat) throws Exception {
String content = getContent(logURI);
Matcher timeMatcher = datePattern.matcher(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
package org.eclipse.cbi.p2repo.aggregator.analyzer.presentation.handlers;

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;

import org.eclipse.cbi.p2repo.util.IOUtils;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

Expand All @@ -25,21 +21,7 @@ public class ClearCacheHandler extends BaseHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
Files.walkFileTree(CACHE, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path directory, IOException exception) throws IOException {
if (exception == null) {
Files.delete(directory);
}
return super.postVisitDirectory(directory, exception);
}
});
IOUtils.delete(CACHE);
} catch (IOException e) {
throw new ExecutionException(e.getLocalizedMessage(), e);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions plugins/org.eclipse.cbi.p2repo.aggregator.edit/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,18 @@ _UI_MavenMapping_versionTemplate_feature = Version Template
_UI_VersionFormat_MavenSnapshot_literal = MavenSnapshot
_UI_Aggregation_mavenBuildNumber_feature = Maven Build Number
_UI_MavenMapping_snapshot_feature = Snapshot
_UI_MavenDependencyItem_type = Maven Dependency Item
_UI_MavenDependencyMapping_type = Maven Dependency Mapping
_UI_Aggregation_mavenDependencyMappings_feature = Maven Dependency Mappings
_UI_Contribution_mavenDependencyMappings_feature = Maven Dependency Mappings
_UI_MavenDependencyItem_groupId_feature = Group Id
_UI_MavenDependencyItem_artifactId_feature = Artifact Id
_UI_MavenDependencyItem_mappedVersionRange_feature = Mapped Version Range
_UI_MavenDependencyItem_mavenDependencyMapping_feature = Maven Dependency Mapping
_UI_MavenDependencyMapping_namespacePattern_feature = Namespace Pattern
_UI_MavenDependencyMapping_namePattern_feature = Name Pattern
_UI_MavenDependencyMapping_groupId_feature = Group Id
_UI_MavenDependencyMapping_artifactId_feature = Artifact Id
_UI_MavenDependencyMapping_versionRangePattern_feature = Version Range Pattern
_UI_MavenDependencyMapping_versionRangeTemplate_feature = Version Range Template
_UI_MavenDependencyMapping_iuNamePattern_feature = IU Name Pattern
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

import org.eclipse.cbi.p2repo.aggregator.util.CapabilityNamespaceImageProvider;
import org.eclipse.cbi.p2repo.p2.RequiredCapability;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.command.CopyCommand.Helper;
import org.eclipse.emf.edit.domain.EditingDomain;

public class RequiredCapabilityItemProvider extends org.eclipse.cbi.p2repo.p2.provider.RequiredCapabilityItemProvider {
public RequiredCapabilityItemProvider(AdapterFactory adapterFactory) {
Expand All @@ -29,4 +34,9 @@ public Object getImage(Object object) {

return overlayImage(object, image);
}

@Override
protected Command createCreateCopyCommand(EditingDomain domain, EObject owner, Helper helper) {
return UnexecutableCommand.INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
import org.eclipse.cbi.p2repo.aggregator.Aggregation;
import org.eclipse.cbi.p2repo.aggregator.AggregatorFactory;
import org.eclipse.cbi.p2repo.aggregator.AggregatorPackage;
import org.eclipse.cbi.p2repo.aggregator.MavenDependencyMapping;
import org.eclipse.cbi.p2repo.aggregator.MavenMapping;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
Expand Down Expand Up @@ -242,8 +245,7 @@ protected void addTypePropertyDescriptor(Object object) {
* <!-- end-user-doc -->
* @generated
*/
@Override
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
private void collectNewChildDescriptorsGen(Collection<Object> newChildDescriptors, Object object) {
super.collectNewChildDescriptors(newChildDescriptors, object);

newChildDescriptors.add(createChildParameter(AggregatorPackage.Literals.AGGREGATION__VALIDATION_SETS,
Expand All @@ -260,6 +262,29 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors

newChildDescriptors.add(createChildParameter(AggregatorPackage.Literals.AGGREGATION__MAVEN_MAPPINGS,
AggregatorFactory.eINSTANCE.createMavenMapping()));

newChildDescriptors.add(createChildParameter(AggregatorPackage.Literals.AGGREGATION__MAVEN_DEPENDENCY_MAPPINGS,
AggregatorFactory.eINSTANCE.createMavenDependencyMapping()));
}

@Override
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
collectNewChildDescriptorsGen(newChildDescriptors, object);

ContributionItemProvider.addNewChildDescriptor(this::createChildParameter, newChildDescriptors,
AggregatorPackage.Literals.AGGREGATION__MAVEN_MAPPINGS,
ContributionItemProvider.createGenericMavenMapping());
ContributionItemProvider.addNewChildDescriptor(this::createChildParameter, newChildDescriptors,
AggregatorPackage.Literals.AGGREGATION__MAVEN_DEPENDENCY_MAPPINGS,
ContributionItemProvider.createJavaPackageMapping());
}

@Override
public String getCreateChildText(Object owner, Object feature, Object child, Collection<?> selection) {
if (child instanceof MavenDependencyMapping || child instanceof MavenMapping) {
return new AdapterFactoryItemDelegator(getRootAdapterFactory()).getText(child);
}
return super.getCreateChildText(owner, feature, child, selection);
}

/**
Expand Down Expand Up @@ -292,6 +317,7 @@ public Collection<? extends EStructuralFeature> getChildrenFeatures(Object objec
childrenFeatures.add(AggregatorPackage.Literals.AGGREGATION__CUSTOM_CATEGORIES);
childrenFeatures.add(AggregatorPackage.Literals.AGGREGATION__CONTACTS);
childrenFeatures.add(AggregatorPackage.Literals.AGGREGATION__MAVEN_MAPPINGS);
childrenFeatures.add(AggregatorPackage.Literals.AGGREGATION__MAVEN_DEPENDENCY_MAPPINGS);
}
return childrenFeatures;
}
Expand Down Expand Up @@ -399,6 +425,7 @@ public void notifyChanged(Notification notification) {
case AggregatorPackage.AGGREGATION__CUSTOM_CATEGORIES:
case AggregatorPackage.AGGREGATION__CONTACTS:
case AggregatorPackage.AGGREGATION__MAVEN_MAPPINGS:
case AggregatorPackage.AGGREGATION__MAVEN_DEPENDENCY_MAPPINGS:
fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,31 @@ public Adapter createMappedRepositoryAdapter() {
return mappedRepositoryItemProvider;
}

/**
* This keeps track of the one adapter used for all {@link org.eclipse.cbi.p2repo.aggregator.MavenDependencyItem} instances.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @since 1.1.0
* @generated
*/
protected MavenDependencyItemItemProvider mavenDependencyItemItemProvider;

/**
* This creates an adapter for a {@link org.eclipse.cbi.p2repo.aggregator.MavenDependencyItem}.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @since 1.1.0
* @generated
*/
@Override
public Adapter createMavenDependencyItemAdapter() {
if (mavenDependencyItemItemProvider == null) {
mavenDependencyItemItemProvider = new MavenDependencyItemItemProvider(this);
}

return mavenDependencyItemItemProvider;
}

/**
* This creates an adapter for a {@link org.eclipse.cbi.p2repo.aggregator.MavenItem}.
* <!-- begin-user-doc -->
Expand Down Expand Up @@ -506,6 +531,31 @@ public Adapter createMavenMappingAdapter() {
return mavenMappingItemProvider;
}

/**
* This keeps track of the one adapter used for all {@link org.eclipse.cbi.p2repo.aggregator.MavenDependencyMapping} instances.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @since 1.1.0
* @generated
*/
protected MavenDependencyMappingItemProvider mavenDependencyMappingItemProvider;

/**
* This creates an adapter for a {@link org.eclipse.cbi.p2repo.aggregator.MavenDependencyMapping}.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @since 1.1.0
* @generated
*/
@Override
public Adapter createMavenDependencyMappingAdapter() {
if (mavenDependencyMappingItemProvider == null) {
mavenDependencyMappingItemProvider = new MavenDependencyMappingItemProvider(this);
}

return mavenDependencyMappingItemProvider;
}

/**
* This creates an adapter for a {@link org.eclipse.cbi.p2repo.aggregator.MetadataRepositoryReference}.
* <!-- begin-user-doc -->
Expand Down Expand Up @@ -615,10 +665,14 @@ public void dispose() {
exclusionRuleItemProvider.dispose();
if (mappedRepositoryItemProvider != null)
mappedRepositoryItemProvider.dispose();
if (mavenDependencyItemItemProvider != null)
mavenDependencyItemItemProvider.dispose();
if (mavenItemItemProvider != null)
mavenItemItemProvider.dispose();
if (mavenMappingItemProvider != null)
mavenMappingItemProvider.dispose();
if (mavenDependencyMappingItemProvider != null)
mavenDependencyMappingItemProvider.dispose();
if (metadataRepositoryReferenceItemProvider != null)
metadataRepositoryReferenceItemProvider.dispose();
if (productItemProvider != null)
Expand Down
Loading

0 comments on commit 73de27b

Please sign in to comment.