Skip to content

Commit 5d3cc20

Browse files
committed
Preparing for interim release
1 parent 16144b9 commit 5d3cc20

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

pom.xml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
<dependency>
6161
<groupId>net.adamcin.sshkey</groupId>
62-
<artifactId>net.adamcin.sshkey.provider.jsch</artifactId>
62+
<artifactId>sshkey-bouncycastle</artifactId>
6363
<version>0.5.0-SNAPSHOT</version>
6464
</dependency>
6565

@@ -72,7 +72,8 @@
7272
<dependency>
7373
<groupId>org.jvnet.hudson.plugins</groupId>
7474
<artifactId>collapsing-console-sections</artifactId>
75-
<version>1.3</version>
75+
<version>1.4.1</version>
76+
<optional>true</optional>
7677
</dependency>
7778

7879
<dependency>
@@ -88,9 +89,15 @@
8889
</dependency>
8990

9091
<dependency>
91-
<groupId>com.jcraft</groupId>
92-
<artifactId>jsch</artifactId>
93-
<version>0.1.50</version>
92+
<groupId>org.bouncycastle</groupId>
93+
<artifactId>bcpkix-jdk15on</artifactId>
94+
<version>1.49</version>
95+
</dependency>
96+
97+
<dependency>
98+
<groupId>org.bouncycastle</groupId>
99+
<artifactId>bcprov-jdk15on</artifactId>
100+
<version>1.49</version>
94101
</dependency>
95102

96103
<dependency>

src/main/java/net/adamcin/jenkins/granite/DeployPackagesBuilder.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public PackId invoke(File f, VirtualChannel channel) throws IOException, Interru
283283
}
284284

285285
Map<PackId, FilePath> selected = new LinkedHashMap<PackId, FilePath>();
286-
for (Map.Entry<String, PackIdFilter> filterEntry : listPackageFilters().entrySet()) {
286+
for (Map.Entry<String, PackIdFilter> filterEntry : listPackageFilters(build, listener).entrySet()) {
287287
boolean matched = false;
288288
for (Map.Entry<PackId, FilePath> entry : found.entrySet()) {
289289
if (filterEntry.getValue().includes(entry.getKey())) {
@@ -320,12 +320,20 @@ public PackId invoke(File f, VirtualChannel channel) throws IOException, Interru
320320
return Collections.unmodifiableMap(selected);
321321
}
322322

323-
private Map<String, PackIdFilter> listPackageFilters() {
323+
public String getPackageIdFilters(AbstractBuild<?, ?> build, TaskListener listener) throws Exception {
324+
return TokenMacro.expandAll(build, listener, getPackageIdFilters());
325+
}
326+
327+
private Map<String, PackIdFilter> listPackageFilters(AbstractBuild<?, ?> build, TaskListener listener) {
324328
Map<String, PackIdFilter> filters = new LinkedHashMap<String, PackIdFilter>();
325-
for (String filter : getPackageIdFilters().split("(\\r)?\\n")) {
326-
if (filter.trim().length() > 0) {
327-
filters.put(filter, DefaultPackIdFilter.parse(filter));
329+
try {
330+
for (String filter : getPackageIdFilters(build, listener).split("(\\r)?\\n")) {
331+
if (filter.trim().length() > 0) {
332+
filters.put(filter, DefaultPackIdFilter.parse(filter));
333+
}
328334
}
335+
} catch (Exception e) {
336+
listener.error("failed to expand tokens in: %n%s", getPackageIdFilters());
329337
}
330338
return Collections.unmodifiableMap(filters);
331339
}

src/main/java/net/adamcin/jenkins/granite/GraniteAnnotatorFactory.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55
import hudson.console.ConsoleAnnotatorFactory;
66
import hudson.model.Run;
77
import org.jvnet.hudson.plugins.collapsingconsolesections.CollapsingSectionAnnotator;
8+
import org.jvnet.hudson.plugins.collapsingconsolesections.CollapsingSectionNote;
9+
import org.jvnet.hudson.plugins.collapsingconsolesections.CollapsingSectionsConfiguration;
810
import org.jvnet.hudson.plugins.collapsingconsolesections.SectionDefinition;
911

10-
@Extension
12+
@Extension(optional = true)
1113
public class GraniteAnnotatorFactory extends ConsoleAnnotatorFactory<Class<Run>> {
1214

1315
@Override
1416
public ConsoleAnnotator newInstance(Class<Run> context) {
15-
SectionDefinition uninstallSection = new SectionDefinition(
17+
CollapsingSectionNote uninstallSection = new CollapsingSectionNote(
1618
"[Granite] Uninstalling package",
1719
"Uninstalling content",
18-
"Package uninstalled");
19-
SectionDefinition installSection = new SectionDefinition(
20+
"Package uninstalled", false);
21+
CollapsingSectionNote installSection = new CollapsingSectionNote(
2022
"[Granite] Installing package",
2123
"Installing content",
22-
"Package uploaded");
23-
return new CollapsingSectionAnnotator(uninstallSection, installSection);
24+
"Package uploaded", false);
25+
return new CollapsingSectionAnnotator(
26+
new CollapsingSectionsConfiguration(
27+
new CollapsingSectionNote[]{uninstallSection, installSection}, false));
2428
}
2529
}

src/main/java/net/adamcin/jenkins/granite/PackageDeploymentCallable.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
import net.adamcin.granite.client.packman.SimpleResponse;
1515
import net.adamcin.granite.client.packman.UnauthorizedException;
1616
import net.adamcin.granite.client.packman.async.AsyncPackageManagerClient;
17+
import net.adamcin.sshkey.api.DefaultKeychain;
18+
import net.adamcin.sshkey.api.Key;
1719
import net.adamcin.sshkey.api.Signer;
18-
import net.adamcin.sshkey.api.SignerException;
20+
import net.adamcin.sshkey.bouncycastle.PEMHelper;
1921

2022
import java.io.File;
2123
import java.io.IOException;
@@ -155,7 +157,7 @@ private boolean handleExisting(AsyncPackageManagerClient client, PackId packId)
155157
return true;
156158
}
157159

158-
private boolean login(AsyncPackageManagerClient client) throws SignerException, IOException {
160+
private boolean login(AsyncPackageManagerClient client) throws IOException {
159161
try {
160162
client.waitForService();
161163
} catch (UnauthorizedException e) {
@@ -167,17 +169,21 @@ private boolean login(AsyncPackageManagerClient client) throws SignerException,
167169
}
168170

169171
if (request.isSshKeyLogin()) {
170-
Signer signer = SignerFactory.getFactoryInstance().getInstance();
171172
List<SSHUserPrivateKey> keys = CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class);
173+
DefaultKeychain keychain = new DefaultKeychain();
172174
for (SSHUserPrivateKey key : keys) {
173-
byte[] passphrase = null;
175+
char[] passphrase = null;
174176
if (key.getPassphrase() != null) {
175-
passphrase = key.getPassphrase().getEncryptedValue().getBytes("UTF-8");
177+
passphrase = key.getPassphrase().getEncryptedValue().toCharArray();
176178
}
177179

178-
signer.addLocalKey(key.getUsername(), key.getPrivateKey().getBytes("UTF-8"), passphrase);
180+
Key sshkey = PEMHelper.readKey(key.getPrivateKey().getBytes("UTF-8"), passphrase);
181+
if (sshkey != null) {
182+
keychain.add(sshkey);
183+
}
179184
}
180185

186+
Signer signer = new Signer(keychain);
181187
return client.login(request.getUsername(), signer);
182188
} else {
183189
return client.login(request.getUsername(), request.getPassword());

0 commit comments

Comments
 (0)