Skip to content

Commit 8e6da4c

Browse files
committed
Reapply "Add sonatype/MavenCentral repository support"
This reverts commit 6c077e8.
1 parent 7c31a87 commit 8e6da4c

43 files changed

Lines changed: 1750 additions & 144 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

biz.aQute.bnd/src/aQute/bnd/main/bnd.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969

7070
import aQute.bnd.build.Container;
7171
import aQute.bnd.build.Project;
72+
import aQute.bnd.build.Project.ReleaseParameter;
7273
import aQute.bnd.build.ProjectBuilder;
7374
import aQute.bnd.build.ProjectLauncher;
7475
import aQute.bnd.build.ProjectLauncher.LiveCoding;
@@ -1501,11 +1502,18 @@ public void _release(releaseOptions options) throws Exception {
15011502
}
15021503

15031504
}
1504-
for (Project p : projects) {
1505+
1506+
for (Iterator<Project> iterator = projects.iterator(); iterator.hasNext();) {
1507+
Project p = iterator.next();
15051508
if (repo != null) {
15061509
p.setProperty(Constants.RELEASEREPO, repo);
15071510
}
1508-
p.release(options.test());
1511+
if (iterator.hasNext()) {
1512+
p.release(options.test());
1513+
} else {
1514+
// releasing last bundle in workspace
1515+
p.release(new ReleaseParameter(null, options.test(), true));
1516+
}
15091517
}
15101518
if (project != null) {
15111519
getInfo(project);

biz.aQute.bndlib/src/aQute/bnd/build/Project.java

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,16 +1142,17 @@ public URI releaseURI(String name, String jarName, InputStream jarStream) throws
11421142
RepositoryPlugin releaseRepo = releaseRepos.get(0); // use only
11431143
// first
11441144
// release repo
1145-
return releaseRepo(releaseRepo, builder, jarName, jarStream);
1145+
return releaseRepo(releaseRepo, builder, jarName, jarStream, false);
11461146
}
11471147
}
11481148

1149-
private URI releaseRepo(RepositoryPlugin releaseRepo, Processor context, String jarName, InputStream jarStream)
1150-
throws Exception {
1149+
private URI releaseRepo(RepositoryPlugin releaseRepo, Processor context, String jarName, InputStream jarStream,
1150+
boolean lastBundleInWorkspace) throws Exception {
11511151
logger.debug("release to {}", releaseRepo.getName());
11521152
try {
11531153
PutOptions putOptions = new RepositoryPlugin.PutOptions();
11541154
// TODO find sub bnd that is associated with this thing
1155+
context.set("startSonatypePublish", Boolean.toString(lastBundleInWorkspace));
11551156
putOptions.context = context;
11561157
PutResult r = releaseRepo.put(jarStream, putOptions);
11571158
logger.debug("Released {} to {} in repository {}", jarName, r.artifact, releaseRepo);
@@ -1213,14 +1214,39 @@ public void release(boolean test) throws Exception {
12131214
* @throws Exception
12141215
*/
12151216
public void release(String name, boolean test) throws Exception {
1216-
List<RepositoryPlugin> releaseRepos = getReleaseRepos(name);
1217+
release(new ReleaseParameter(name, test, false));
1218+
}
1219+
1220+
@Deprecated(forRemoval = true, since = "7.3.0")
1221+
public static class ReleaseParameter {
1222+
@Deprecated
1223+
public String name;
1224+
@Deprecated
1225+
public boolean test;
1226+
@Deprecated
1227+
public boolean lastBundleInWorkspace;
1228+
1229+
@Deprecated(forRemoval = true, since = "7.3.0")
1230+
public ReleaseParameter(String name, boolean test, boolean lastBundleInWorkspace) {
1231+
this.name = name;
1232+
this.test = test;
1233+
this.lastBundleInWorkspace = lastBundleInWorkspace;
1234+
}
1235+
}
1236+
1237+
/**
1238+
* Do not use this method.
1239+
*/
1240+
@Deprecated(forRemoval = true, since = "7.3.0")
1241+
public void release(ReleaseParameter relParam) throws Exception, IOException {
1242+
List<RepositoryPlugin> releaseRepos = getReleaseRepos(relParam.name);
12171243
if (releaseRepos.isEmpty()) {
12181244
return;
12191245
}
12201246
logger.debug("release");
12211247
File[] jars = getBuildFiles(false);
12221248
if (jars == null) {
1223-
jars = build(test);
1249+
jars = build(relParam.test);
12241250
// If build fails jars will be null
12251251
if (jars == null) {
12261252
logger.debug("no jars built");
@@ -1232,9 +1258,17 @@ public void release(String name, boolean test) throws Exception {
12321258
try (ProjectBuilder builder = getBuilder(null)) {
12331259
builder.init();
12341260
for (RepositoryPlugin releaseRepo : releaseRepos) {
1235-
for (File jar : jars) {
1261+
for (int i = 0; i < jars.length; i++) {
1262+
File jar = jars[i];
12361263
try (InputStream jarStream = new BufferedInputStream(IO.stream(jar))) {
1237-
releaseRepo(releaseRepo, builder, jar.getName(), jarStream);
1264+
if (relParam.lastBundleInWorkspace && i == jars.length - 1) {
1265+
// this is the last jar builded inside bnd workspace
1266+
// and if appropriate "-sub" - the last of builded
1267+
// sub-bundles
1268+
releaseRepo(releaseRepo, builder, jar.getName(), jarStream, true);
1269+
} else {
1270+
releaseRepo(releaseRepo, builder, jar.getName(), jarStream, false);
1271+
}
12381272
}
12391273
}
12401274
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*/
3-
@Version("4.7.2")
3+
@Version("4.7.1")
44
package aQute.bnd.build;
55

66
import org.osgi.annotation.versioning.Version;

biz.aQute.repository/src/aQute/bnd/repository/maven/provider/Configuration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,9 @@ public interface Configuration {
8181
* @return a comma separated list of tags.
8282
*/
8383
String tags();
84+
85+
/**
86+
* @return SonatypeMode for this repository none, manual or autopublish
87+
*/
88+
SonatypeMode sonatypeMode(String deflt);
8489
}

biz.aQute.repository/src/aQute/bnd/repository/maven/provider/MavenBndRepository.java

Lines changed: 83 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.io.UnsupportedEncodingException;
1313
import java.net.URI;
1414
import java.net.URLDecoder;
15+
import java.util.ArrayList;
1516
import java.util.Arrays;
1617
import java.util.Collection;
1718
import java.util.Collections;
@@ -99,13 +100,20 @@
99100
@BndPlugin(name = "MavenBndRepository", parameters = Configuration.class)
100101
public class MavenBndRepository extends BaseRepository implements RepositoryPlugin, RegistryPlugin, Plugin, Closeable,
101102
Refreshable, Actionable, ToDependencyPom, ReleaseBracketingPlugin {
102-
final static Pattern PREPROCESS_P = Pattern.compile("\\{\\s*(?<core>[^}]+)\\s*\\}");
103103

104-
private final static Logger logger = LoggerFactory.getLogger(MavenBndRepository.class);
105-
private static final int DEFAULT_POLL_TIME = 5;
104+
public static final String SONATYPE_RELEASE_DIR = "cnf/cache/sonatype-release";
105+
public static final String SONATYPE_SNAPSHOT_DIR = "cnf/cache/sonatype-snapshot";
106+
public static final String SONATYPE_DEPLOYMENTID_FILE = "deploymendID.txt";
106107

107-
private static final String NONE = "NONE";
108-
private static final String MAVEN_REPO_LOCAL = System.getProperty("maven.repo.local",
108+
final static Pattern PREPROCESS_P = Pattern
109+
.compile("\\{\\s*(?<core>[^}]+)\\s*\\}");
110+
111+
private final static Logger logger = LoggerFactory
112+
.getLogger(MavenBndRepository.class);
113+
private static final int DEFAULT_POLL_TIME = 5;
114+
115+
private static final String NONE = "NONE";
116+
private static final String MAVEN_REPO_LOCAL = System.getProperty("maven.repo.local",
109117
"~/.m2/repository");
110118
private Configuration configuration;
111119
private Registry registry;
@@ -115,16 +123,16 @@ public class MavenBndRepository extends BaseRepository implements RepositoryPlug
115123
private boolean inited;
116124
IndexFile index;
117125
private ScheduledFuture<?> indexPoller;
118-
private RepoActions actions = new RepoActions(this);
126+
private RepoActions actions = new RepoActions(this);
119127
private String name;
120128
private HttpClient client;
121-
private ReleasePluginImpl releasePlugin = new ReleasePluginImpl(this, null);
122-
private File base = IO.work;
123-
private String status = null;
129+
private ReleasePluginImpl releasePlugin = new ReleasePluginImpl(this, null);
130+
private File base = IO.work;
131+
private String status = null;
124132
private boolean remote;
125-
private final AtomicReference<Throwable> open = new AtomicReference<>();
133+
private final AtomicReference<Throwable> open = new AtomicReference<>();
126134
Optional<Workspace> workspace;
127-
private AtomicBoolean polling = new AtomicBoolean(false);
135+
private AtomicBoolean polling = new AtomicBoolean(false);
128136

129137
/**
130138
* Put result
@@ -282,8 +290,7 @@ private void doExtra(PutOptions options, ReleaseDTO instructions, IPom pom, Rele
282290
String clazz = extra.clazz;
283291
File file = new File(path);
284292
if (!file.isFile())
285-
reporter.error("-release-maven archive contains a path to a file that does not exist: %s",
286-
file);
293+
reporter.error("-release-maven archive contains a path to a file that does not exist: %s", file);
287294
else {
288295
try (Resource r = new FileResource(file)) {
289296
Resource what;
@@ -487,7 +494,6 @@ private ReleaseDTO getReleaseDTO(Processor context) {
487494
release.passphrase = sign.get("passphrase");
488495
}
489496

490-
491497
int clazz = 0;
492498

493499
for (Iterator<Entry<String, Attrs>> it = p.entrySet()
@@ -515,8 +521,7 @@ private ReleaseDTO getReleaseDTO(Processor context) {
515521
.getAbsolutePath();
516522
} else {
517523
reporter.warning(
518-
"The -maven-release instruction has an 'archive' without the path attribute: %s",
519-
e);
524+
"The -maven-release instruction has an 'archive' without the path attribute: %s", e);
520525
continue;
521526
}
522527
extra.path = path;
@@ -649,18 +654,60 @@ synchronized boolean init() {
649654
inited = true;
650655

651656
try {
652-
List<MavenBackingRepository> release = MavenBackingRepository.create(configuration.releaseUrl(), reporter,
653-
localRepo, client);
654-
List<MavenBackingRepository> snapshot = MavenBackingRepository.create(configuration.snapshotUrl(), reporter,
655-
localRepo, client);
656-
657+
List<MavenBackingRepository> release = new ArrayList<MavenBackingRepository>();
657658
MavenBackingRepository staging = null;
658-
659-
if (configuration.stagingUrl() != null) {
660-
staging = MavenBackingRepository.getBackingRepository(configuration.stagingUrl(),
661-
reporter, localRepo, client);
659+
List<MavenBackingRepository> snapshot = new ArrayList<MavenBackingRepository>();
660+
661+
String releaseUrl = configuration.releaseUrl();
662+
SonatypeMode sonatypeMode = configuration.sonatypeMode(SonatypeMode.NONE.name());
663+
664+
String stagingUrl = configuration.stagingUrl();
665+
String snapshotUrl = configuration.snapshotUrl();
666+
667+
String sonatypeReleaseUrl = null;
668+
String sonatypeSnapshotUrl = null;
669+
switch (sonatypeMode) {
670+
case MANUAL, AUTOPUBLISH -> {
671+
logger.info("deployment via Sonatype Central Portal configured in {} mode", sonatypeMode);
672+
File releaseDir = registry.getPlugin(Workspace.class)
673+
.getFile(SONATYPE_RELEASE_DIR);
674+
File snapshotDir = registry.getPlugin(Workspace.class)
675+
.getFile(SONATYPE_SNAPSHOT_DIR);
676+
if (stagingUrl == null) {
677+
logger.debug("deployment via relase url to Sonatype Portal configured");
678+
List<MavenBackingRepository> releaseLocal = MavenBackingRepository.create(releaseDir.toURI()
679+
.toString(), reporter, localRepo, client);
680+
release.addAll(releaseLocal);
681+
sonatypeReleaseUrl = releaseUrl;
682+
} else {
683+
logger.debug("deployment via staging url to Sonatype Portal configured");
684+
release = MavenBackingRepository.create(releaseUrl, reporter, localRepo, client);
685+
staging = MavenBackingRepository.getBackingRepository(releaseDir.toURI()
686+
.toString(), reporter, localRepo, client);
687+
sonatypeReleaseUrl = stagingUrl;
688+
}
689+
if (snapshotUrl != null) {
690+
logger.debug("deployment via snapshot url to Sonatype Portal configured");
691+
List<MavenBackingRepository> snapshotLocal = MavenBackingRepository.create(snapshotDir.toURI()
692+
.toString(), reporter, localRepo, client);
693+
snapshot.addAll(snapshotLocal);
694+
sonatypeSnapshotUrl = snapshotUrl;
695+
}
696+
}
697+
case NONE -> {
698+
if (stagingUrl == null) {
699+
release = MavenBackingRepository.create(releaseUrl, reporter, localRepo, client);
700+
} else {
701+
release = MavenBackingRepository.create(releaseUrl, reporter, localRepo, client);
702+
staging = MavenBackingRepository.getBackingRepository(stagingUrl, reporter, localRepo, client);
703+
}
704+
if (snapshotUrl != null) {
705+
snapshot = MavenBackingRepository.create(snapshotUrl, reporter, localRepo, client);
706+
}
707+
}
662708
}
663709

710+
664711
for (MavenBackingRepository mbr : release) {
665712
if (mbr.isRemote()) {
666713
remote = true;
@@ -675,9 +722,14 @@ synchronized boolean init() {
675722
}
676723
}
677724

678-
storage = new MavenRepository(localRepo, name, release, staging, snapshot,
679-
client.promiseFactory()
725+
storage = new MavenRepository(localRepo, name, release, staging, snapshot, client.promiseFactory()
680726
.executor(), reporter);
727+
MavenRepository storageMvn = (MavenRepository) storage;
728+
storageMvn.setSonatypeMode(sonatypeMode);
729+
if (sonatypeReleaseUrl != null) {
730+
storageMvn.setSonatypePublisherUrl(sonatypeReleaseUrl);
731+
storageMvn.setSonatypePublishSnapshotUrl(sonatypeSnapshotUrl);
732+
}
681733

682734
File indexFile = getIndexFile();
683735
Processor domain = (registry != null) ? registry.getPlugin(Processor.class) : null;
@@ -1085,4 +1137,8 @@ public boolean isRemote() {
10851137
return remote;
10861138
}
10871139

1140+
public HttpClient getClient() {
1141+
return client;
1142+
}
1143+
10881144
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package aQute.bnd.repository.maven.provider;
2+
3+
@Deprecated(forRemoval = true, since = "7.3.0")
4+
public enum SonatypeMode {
5+
6+
/*
7+
* No special Sonatype Portal handling
8+
*/
9+
NONE("none"),
10+
11+
/*
12+
* Manual mode where artifacts are staged but not published
13+
*/
14+
MANUAL("manual"),
15+
16+
/*
17+
* Automatic publishing after upload and validatíon
18+
*/
19+
AUTOPUBLISH("autopublish");
20+
21+
private final String value;
22+
23+
SonatypeMode(String value) {
24+
this.value = value;
25+
}
26+
27+
@Deprecated
28+
@Override
29+
public String toString() {
30+
return value;
31+
}
32+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@Version("2.3.1")
1+
@Version("2.3.0")
22
package aQute.bnd.repository.maven.provider;
33

44
import org.osgi.annotation.versioning.Version;

biz.aQute.repository/src/aQute/maven/provider/MavenBackingRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ static public MavenBackingRepository getBackingRepository(String url, Reporter r
231231
if (uri.getScheme()
232232
.equalsIgnoreCase("file")) {
233233
File remote = new File(uri);
234-
return new MavenFileRepository(localRepo, remote, reporter);
234+
MavenFileRepository fileRepo = new MavenFileRepository(localRepo, remote, reporter);
235+
fileRepo.setClient(client);
236+
return fileRepo;
235237
} else {
236238
return new MavenRemoteRepository(localRepo, client, url, reporter);
237239
}

0 commit comments

Comments
 (0)