Skip to content

Commit

Permalink
Adjust according to review
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 authored and mickaelistria committed Oct 5, 2020
1 parent 8d2f590 commit cb06d36
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@
import org.eclipse.pde.ui.target.ITargetLocationWizard;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
Expand All @@ -41,7 +38,6 @@ public class MavenTargetLocationWizard extends Wizard implements ITargetLocation
private Text groupId;
private Text version;
private CCombo type;
private Button includeDependencies;
private MavenTargetLocation targetLocation;
private CCombo scope;
private ComboViewer metadata;
Expand Down Expand Up @@ -72,7 +68,7 @@ public void createControl(Composite parent) {
type = new CCombo(composite, SWT.BORDER);
type.add("jar");
type.add("bundle");
new Label(composite, SWT.NONE).setText("Missing Metadata");
new Label(composite, SWT.NONE).setText("Missing OSGi-Manifest");
metadata = new ComboViewer(composite);
metadata.setContentProvider(ArrayContentProvider.getInstance());
metadata.setLabelProvider(new ColumnLabelProvider() {
Expand All @@ -86,41 +82,23 @@ public String getText(Object element) {

});
metadata.setInput(MissingMetadataMode.values());
new Label(composite, SWT.NONE).setText("Include dependecies");
includeDependencies = new Button(composite, SWT.CHECK);
new Label(composite, SWT.NONE).setText("Dependency scope");
new Label(composite, SWT.NONE).setText("Dependencies scope");
scope = new CCombo(composite, SWT.BORDER);
scope.add("");
scope.add("compile");
scope.add("test");
scope.add("provided");
scope.setEnabled(false);
includeDependencies.addSelectionListener(new SelectionListener() {

@Override
public void widgetSelected(SelectionEvent e) {
scope.setEnabled(includeDependencies.getSelection());
}

@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
if (targetLocation != null) {
artifactId.setText(targetLocation.getArtifactId());
groupId.setText(targetLocation.getGroupId());
version.setText(targetLocation.getVersion());
boolean include = targetLocation.isIncludeDependencies();
includeDependencies.setSelection(include);
type.setText(targetLocation.getArtifactType());
scope.setText(targetLocation.getDependencyScope());
scope.setEnabled(include);
metadata.setSelection(new StructuredSelection(targetLocation.getMetadataMode()));
} else {
artifactId.setText("");
groupId.setText("");
version.setText("");
includeDependencies.setSelection(false);
type.setText(MavenTargetLocation.DEFAULT_PACKAGE_TYPE);
scope.setText(MavenTargetLocation.DEFAULT_DEPENDENCY_SCOPE);
metadata.setSelection(new StructuredSelection(MavenTargetLocation.DEFAULT_METADATA_MODE));
Expand Down Expand Up @@ -157,14 +135,14 @@ public boolean performFinish() {
if (targetLocation == null) {
targetLocation = new MavenTargetLocation(groupId.getText(), artifactId.getText(), version.getText(),
type.getText(), (MissingMetadataMode) metadata.getStructuredSelection().getFirstElement(),
includeDependencies.getSelection(), scope.getText());
scope.getText());
} else {
ITargetLocation[] locations = targetDefinition.getTargetLocations().clone();
for (int i = 0; i < locations.length; i++) {
if (locations[i] == targetLocation) {
locations[i] = new MavenTargetLocation(groupId.getText(), artifactId.getText(), version.getText(),
type.getText(), (MissingMetadataMode) metadata.getStructuredSelection().getFirstElement(),
includeDependencies.getSelection(), scope.getText());
scope.getText());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public MavenTargetBundle(Artifact artifact, MissingMetadataMode metadataMode) {
if (metadataMode == MissingMetadataMode.ERROR) {
status = new Status(Status.ERROR, MavenTargetBundle.class.getPackage().getName(),
artifact + " is not a bundle", ex);
} else if (metadataMode == MissingMetadataMode.AUTOMATED) {
} else if (metadataMode == MissingMetadataMode.GENERATE) {
try {
bundle = getWrappedArtifact(artifact, bundleInfo);
isWrapped = true;
Expand Down Expand Up @@ -144,7 +144,7 @@ public static String createBundleVersion(Artifact artifact) {

public static String createSymbolicName(Artifact artifact) {

return "packed.by.m2e." + artifact.getGroupId() + "." + artifact.getArtifactId();
return "wrapped." + artifact.getGroupId() + "." + artifact.getArtifactId();
}

public boolean isWrapped() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.apache.maven.RepositoryUtils;
Expand Down Expand Up @@ -48,19 +49,17 @@ public class MavenTargetLocation extends AbstractBundleContainer {
public static final String ELEMENT_VERSION = "version";
public static final String ELEMENT_ARTIFACT_ID = "artifactId";
public static final String ELEMENT_GROUP_ID = "groupId";
public static final String ATTRIBUTE_DEPENDENCY_SCOPE = "dependencyScope";
public static final String ATTRIBUTE_INCLUDE_DEPENDENCIES = "includeDependencies";
public static final String ATTRIBUTE_MISSING_META_DATA = "missingMetaData";
public static final String DEFAULT_DEPENDENCY_SCOPE = "compile";
public static final MissingMetadataMode DEFAULT_METADATA_MODE = MissingMetadataMode.AUTOMATED;
public static final String ATTRIBUTE_DEPENDENCY_SCOPE = "includeDependencyScope";
public static final String ATTRIBUTE_MISSING_META_DATA = "missingManfiest";
public static final String DEFAULT_DEPENDENCY_SCOPE = "";
public static final MissingMetadataMode DEFAULT_METADATA_MODE = MissingMetadataMode.GENERATE;
public static final String DEFAULT_PACKAGE_TYPE = "jar";
public static final String DEPENDENCYNODE_IS_ROOT = "dependencynode.root";
public static final String DEPENDENCYNODE_PARENT = "dependencynode.parent";

private final String artifactId;
private final String groupId;
private final String version;
private final boolean includeDependencies;
private final String artifactType;
private final String dependencyScope;
private final MissingMetadataMode metadataMode;
Expand All @@ -71,13 +70,12 @@ public class MavenTargetLocation extends AbstractBundleContainer {
private Set<Artifact> failedArtifacts = new HashSet<>();

public MavenTargetLocation(String groupId, String artifactId, String version, String artifactType,
MissingMetadataMode metadataMode, boolean includeDependencies, String dependencyScope) {
MissingMetadataMode metadataMode, String dependencyScope) {
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.artifactType = artifactType;
this.metadataMode = metadataMode;
this.includeDependencies = includeDependencies;
this.dependencyScope = dependencyScope;
}

Expand All @@ -92,7 +90,7 @@ protected TargetBundle[] resolveBundles(ITargetDefinition definition, IProgressM
Artifact artifact = RepositoryUtils.toArtifact(maven.resolve(getGroupId(), getArtifactId(), getVersion(),
getArtifactType(), null, repositories, monitor));
if (artifact != null) {
if (includeDependencies) {
if (dependencyScope != null && !dependencyScope.isBlank()) {
IMavenExecutionContext context = maven.createExecutionContext();
PreorderNodeListGenerator dependecies = context.execute(new ICallable<PreorderNodeListGenerator>() {

Expand All @@ -101,7 +99,7 @@ public PreorderNodeListGenerator call(IMavenExecutionContext context, IProgressM
throws CoreException {
try {
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, getDependencyScope()));
collectRequest.setRoot(new Dependency(artifact, dependencyScope));
collectRequest.setRepositories(RepositoryUtils.toRepos(repositories));

RepositorySystem repoSystem = MavenPluginActivator.getDefault().getRepositorySystem();
Expand Down Expand Up @@ -189,42 +187,28 @@ public String getLocation(boolean resolve) throws CoreException {

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((artifactId == null) ? 0 : artifactId.hashCode());
result = prime * result + ((groupId == null) ? 0 : groupId.hashCode());
result = prime * result + (includeDependencies ? 1231 : 1237);
result = prime * result + ((version == null) ? 0 : version.hashCode());
return result;
return Objects.hash(artifactId, artifactType, dependencyNodes, dependencyScope, failedArtifacts, groupId,
ignoredArtifacts, metadataMode, targetBundles, version);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
MavenTargetLocation other = (MavenTargetLocation) obj;
if (artifactId == null) {
if (other.artifactId != null)
return false;
} else if (!artifactId.equals(other.artifactId))
return false;
if (groupId == null) {
if (other.groupId != null)
return false;
} else if (!groupId.equals(other.groupId))
return false;
if (includeDependencies != other.includeDependencies)
return false;
if (version == null) {
if (other.version != null)
return false;
} else if (!version.equals(other.version))
return false;
return true;
return Objects.equals(artifactId, other.artifactId) && Objects.equals(artifactType, other.artifactType)
&& Objects.equals(dependencyNodes, other.dependencyNodes)
&& Objects.equals(dependencyScope, other.dependencyScope)
&& Objects.equals(failedArtifacts, other.failedArtifacts) && Objects.equals(groupId, other.groupId)
&& Objects.equals(ignoredArtifacts, other.ignoredArtifacts) && metadataMode == other.metadataMode
&& Objects.equals(targetBundles, other.targetBundles) && Objects.equals(version, other.version);
}

@Override
Expand All @@ -234,10 +218,10 @@ public String serialize() {
xml.append(getType());
xml.append("\" " + ATTRIBUTE_MISSING_META_DATA + "=\"");
xml.append(metadataMode.name().toLowerCase());
xml.append("\" " + ATTRIBUTE_INCLUDE_DEPENDENCIES + "=\"");
xml.append(includeDependencies);
xml.append("\" " + ATTRIBUTE_DEPENDENCY_SCOPE + "=\"");
xml.append(dependencyScope);
if (dependencyScope != null && !dependencyScope.isBlank()) {
xml.append(dependencyScope);
}
xml.append("\" >");
xml.append("<" + ELEMENT_GROUP_ID + ">");
xml.append(groupId);
Expand Down Expand Up @@ -267,10 +251,6 @@ public String getVersion() {
return version;
}

public boolean isIncludeDependencies() {
return includeDependencies;
}

public MissingMetadataMode getMetadataMode() {
if (metadataMode == null) {
return DEFAULT_METADATA_MODE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,14 @@ public ITargetLocation getTargetLocation(String type, String serializedXML) thro
Document document = docBuilder
.parse(new ByteArrayInputStream(serializedXML.getBytes(StandardCharsets.UTF_8)));
Element location = document.getDocumentElement();
boolean includeDependencies = Boolean
.parseBoolean(location.getAttribute(MavenTargetLocation.ATTRIBUTE_INCLUDE_DEPENDENCIES));
MissingMetadataMode mode = MissingMetadataMode
.valueOf(location.getAttribute(MavenTargetLocation.ATTRIBUTE_MISSING_META_DATA).toUpperCase());
String dependencyScope = location.getAttribute(MavenTargetLocation.ATTRIBUTE_DEPENDENCY_SCOPE);
String artifactId = getText(MavenTargetLocation.ELEMENT_ARTIFACT_ID, location);
String groupId = getText(MavenTargetLocation.ELEMENT_GROUP_ID, location);
String version = getText(MavenTargetLocation.ELEMENT_VERSION, location);
String artifactType = getText(MavenTargetLocation.ELEMENT_TYPE, location);
return new MavenTargetLocation(groupId, artifactId, version, artifactType, mode, includeDependencies,
dependencyScope);
return new MavenTargetLocation(groupId, artifactId, version, artifactType, mode, dependencyScope);
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, MavenTargetLocationFactory.class.getPackage().getName(),
e.getMessage(), e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
package org.eclipse.m2e.pde;

public enum MissingMetadataMode {
IGNORE, ERROR, AUTOMATED;
IGNORE, ERROR, GENERATE;
}

0 comments on commit cb06d36

Please sign in to comment.