forked from bndtools/bnd
/
AbstractMavenRepository.java
94 lines (71 loc) · 2.49 KB
/
AbstractMavenRepository.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package bndtools.m2e;
import java.io.File;
import java.io.InputStream;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.project.IMavenProjectChangedListener;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
import org.eclipse.osgi.service.datalocation.Location;
import org.osgi.service.repository.Repository;
import aQute.bnd.osgi.repository.BaseRepository;
import aQute.bnd.service.RepositoryPlugin;
public abstract class AbstractMavenRepository extends BaseRepository
implements Repository, RepositoryPlugin, IMavenProjectChangedListener {
final IMavenProjectRegistry mavenProjectRegistry;
protected AbstractMavenRepository(IMavenProjectRegistry mavenProjectRegistry) {
this.mavenProjectRegistry = mavenProjectRegistry;
}
@Override
public boolean canWrite() {
return false;
}
@Override
public String getLocation() {
Location location = Platform.getInstanceLocation();
if (location != null) {
return location.getURL()
.toString();
}
return null;
}
@Override
public PutResult put(InputStream stream, PutOptions options) throws Exception {
throw new IllegalStateException(getName() + " is read-only");
}
File guessBundleFile(IMavenProjectFacade projectFacade) {
String buildDirectoryGuess;
IProject project = projectFacade.getProject();
IPath outputLocation = projectFacade.getOutputLocation();
if (outputLocation.segment(0)
.equals(project.getFullPath()
.segment(0))) {
outputLocation = outputLocation.removeFirstSegments(1);
}
IFolder folder = project.getFolder(outputLocation.toString());
if (folder.exists()) {
outputLocation = folder.getLocation();
}
if (outputLocation != null) {
if (outputLocation.lastSegment()
.equals("classes")) {
outputLocation = outputLocation.removeLastSegments(1);
}
buildDirectoryGuess = outputLocation.toOSString();
} else {
buildDirectoryGuess = projectFacade.getProject()
.getLocation()
.toOSString() + "/target";
}
ArtifactKey artifactKey = projectFacade.getArtifactKey();
String finalNameGuess = buildDirectoryGuess + "/" + artifactKey.getArtifactId() + "-" + artifactKey.getVersion()
+ ".jar";
return new File(finalNameGuess);
}
void cleanup() {
mavenProjectRegistry.removeMavenProjectChangedListener(this);
}
}