-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/blackducksoftware/synopsy…
- Loading branch information
Showing
37 changed files
with
1,391 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ava/com/synopsys/integration/detectable/detectable/executable/resolver/LernaResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* detectable | ||
* | ||
* Copyright (c) 2020 Synopsys, Inc. | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.synopsys.integration.detectable.detectable.executable.resolver; | ||
|
||
import java.io.File; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.synopsys.integration.detectable.detectable.exception.DetectableException; | ||
|
||
public interface LernaResolver { | ||
@Nullable | ||
File resolveLerna() throws DetectableException; | ||
} |
99 changes: 99 additions & 0 deletions
99
.../src/main/java/com/synopsys/integration/detectable/detectables/lerna/LernaDetectable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* detectable | ||
* | ||
* Copyright (c) 2020 Synopsys, Inc. | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.synopsys.integration.detectable.detectables.lerna; | ||
|
||
import java.io.File; | ||
|
||
import com.synopsys.integration.detectable.Detectable; | ||
import com.synopsys.integration.detectable.DetectableEnvironment; | ||
import com.synopsys.integration.detectable.Extraction; | ||
import com.synopsys.integration.detectable.ExtractionEnvironment; | ||
import com.synopsys.integration.detectable.detectable.annotation.DetectableInfo; | ||
import com.synopsys.integration.detectable.detectable.exception.DetectableException; | ||
import com.synopsys.integration.detectable.detectable.executable.resolver.LernaResolver; | ||
import com.synopsys.integration.detectable.detectable.file.FileFinder; | ||
import com.synopsys.integration.detectable.detectable.result.DetectableResult; | ||
import com.synopsys.integration.detectable.detectable.result.ExecutableNotFoundDetectableResult; | ||
import com.synopsys.integration.detectable.detectable.result.FileNotFoundDetectableResult; | ||
import com.synopsys.integration.detectable.detectable.result.FilesNotFoundDetectableResult; | ||
import com.synopsys.integration.detectable.detectable.result.PassedDetectableResult; | ||
import com.synopsys.integration.detectable.detectables.npm.lockfile.NpmPackageLockDetectable; | ||
import com.synopsys.integration.detectable.detectables.npm.lockfile.NpmShrinkwrapDetectable; | ||
import com.synopsys.integration.detectable.detectables.yarn.YarnLockDetectable; | ||
|
||
@DetectableInfo(language = "Node JS", forge = "npmjs", requirementsMarkdown = "File: " + LernaDetectable.PACKAGE_JSON + ", and one of the following: " + LernaDetectable.PACKAGE_LOCK_JSON + ", " + LernaDetectable.SHRINKWRAP_JSON + ", " | ||
+ LernaDetectable.YARN_LOCK + ".") | ||
public class LernaDetectable extends Detectable { | ||
public static final String LERNA_JSON = "lerna.json"; | ||
public static final String PACKAGE_JSON = NpmPackageLockDetectable.PACKAGE_JSON; | ||
public static final String PACKAGE_LOCK_JSON = NpmPackageLockDetectable.PACKAGE_LOCK_JSON; | ||
public static final String SHRINKWRAP_JSON = NpmShrinkwrapDetectable.SHRINKWRAP_JSON; | ||
public static final String YARN_LOCK = YarnLockDetectable.YARN_LOCK_FILENAME; | ||
|
||
private final FileFinder fileFinder; | ||
private final LernaResolver lernaResolver; | ||
private final LernaExtractor lernaExtractor; | ||
|
||
private File lernaExecutable; | ||
|
||
public LernaDetectable(DetectableEnvironment environment, FileFinder fileFinder, LernaResolver lernaResolver, LernaExtractor lernaExtractor) { | ||
super(environment); | ||
this.fileFinder = fileFinder; | ||
this.lernaResolver = lernaResolver; | ||
this.lernaExtractor = lernaExtractor; | ||
} | ||
|
||
@Override | ||
public DetectableResult applicable() { | ||
File lernaJsonFile = fileFinder.findFile(environment.getDirectory(), LERNA_JSON); | ||
|
||
if (lernaJsonFile == null) { | ||
return new FileNotFoundDetectableResult(LERNA_JSON); | ||
} | ||
|
||
return new PassedDetectableResult(); | ||
} | ||
|
||
@Override | ||
public DetectableResult extractable() throws DetectableException { | ||
// Lerna is used in conjunction with traditional NPM projects or Yarn projects. | ||
File packageLockFile = fileFinder.findFile(environment.getDirectory(), PACKAGE_LOCK_JSON); | ||
File shrinkwrapFile = fileFinder.findFile(environment.getDirectory(), SHRINKWRAP_JSON); | ||
File yarnLockFile = fileFinder.findFile(environment.getDirectory(), YARN_LOCK); | ||
if (packageLockFile == null && shrinkwrapFile == null && yarnLockFile == null) { | ||
return new FilesNotFoundDetectableResult(PACKAGE_LOCK_JSON, YARN_LOCK); | ||
} | ||
|
||
lernaExecutable = lernaResolver.resolveLerna(); | ||
if (lernaExecutable == null) { | ||
return new ExecutableNotFoundDetectableResult("lerna"); | ||
} | ||
|
||
return new PassedDetectableResult(); | ||
} | ||
|
||
@Override | ||
public Extraction extract(ExtractionEnvironment extractionEnvironment) { | ||
return lernaExtractor.extract(environment, lernaExecutable); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...e/src/main/java/com/synopsys/integration/detectable/detectables/lerna/LernaExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* detectable | ||
* | ||
* Copyright (c) 2020 Synopsys, Inc. | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.synopsys.integration.detectable.detectables.lerna; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import com.synopsys.integration.detectable.DetectableEnvironment; | ||
import com.synopsys.integration.detectable.Extraction; | ||
import com.synopsys.integration.detectable.detectables.lerna.model.LernaPackage; | ||
import com.synopsys.integration.detectable.detectables.lerna.model.LernaResult; | ||
|
||
public class LernaExtractor { | ||
private final LernaPackageDiscoverer lernaPackageDiscoverer; | ||
private final LernaPackager lernaPackager; | ||
|
||
public LernaExtractor(LernaPackageDiscoverer lernaPackageDiscoverer, LernaPackager lernaPackager) { | ||
this.lernaPackageDiscoverer = lernaPackageDiscoverer; | ||
this.lernaPackager = lernaPackager; | ||
} | ||
|
||
public Extraction extract(DetectableEnvironment detectableEnvironment, File lernaExecutable) { | ||
File sourceDirectory = detectableEnvironment.getDirectory(); | ||
|
||
try { | ||
List<LernaPackage> lernaPackages = lernaPackageDiscoverer.discoverLernaPackages(sourceDirectory, lernaExecutable); | ||
LernaResult lernaResult = lernaPackager.generateLernaResult(sourceDirectory, lernaPackages); | ||
|
||
if (lernaResult.getException().isPresent()) { | ||
throw lernaResult.getException().get(); | ||
} | ||
|
||
return new Extraction.Builder() | ||
.projectName(lernaResult.getProjectName()) | ||
.projectVersion(lernaResult.getProjectVersionName()) | ||
.success(lernaResult.getCodeLocations()) | ||
.build(); | ||
} catch (Exception e) { | ||
return new Extraction.Builder().exception(e).build(); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ble/src/main/java/com/synopsys/integration/detectable/detectables/lerna/LernaOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* detectable | ||
* | ||
* Copyright (c) 2020 Synopsys, Inc. | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.synopsys.integration.detectable.detectables.lerna; | ||
|
||
public class LernaOptions { | ||
private final boolean includePrivatePackages; | ||
|
||
public LernaOptions(boolean includePrivatePackages) { | ||
this.includePrivatePackages = includePrivatePackages; | ||
} | ||
|
||
public boolean shouldIncludePrivatePackages() { | ||
return includePrivatePackages; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...in/java/com/synopsys/integration/detectable/detectables/lerna/LernaPackageDiscoverer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* detectable | ||
* | ||
* Copyright (c) 2020 Synopsys, Inc. | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.synopsys.integration.detectable.detectables.lerna; | ||
|
||
import java.io.File; | ||
import java.lang.reflect.Type; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.reflect.TypeToken; | ||
import com.synopsys.integration.detectable.detectable.executable.ExecutableOutput; | ||
import com.synopsys.integration.detectable.detectable.executable.ExecutableRunner; | ||
import com.synopsys.integration.detectable.detectable.executable.ExecutableRunnerException; | ||
import com.synopsys.integration.detectable.detectables.lerna.model.LernaPackage; | ||
|
||
public class LernaPackageDiscoverer { | ||
private final ExecutableRunner executableRunner; | ||
private final Gson gson; | ||
|
||
public LernaPackageDiscoverer(ExecutableRunner executableRunner, Gson gson) { | ||
this.executableRunner = executableRunner; | ||
this.gson = gson; | ||
} | ||
|
||
public List<LernaPackage> discoverLernaPackages(File workingDirectory, File lernaExecutable) throws ExecutableRunnerException { | ||
ExecutableOutput lernaLsExecutableOutput = executableRunner.execute(workingDirectory, lernaExecutable, "ls", "--all", "--json"); | ||
String lernaLsOutput = lernaLsExecutableOutput.getStandardOutput(); | ||
|
||
Type lernaPackageListType = new TypeToken<ArrayList<LernaPackage>>() {}.getType(); | ||
List<LernaPackage> lernaPackages = gson.fromJson(lernaLsOutput, lernaPackageListType); | ||
|
||
return lernaPackages.stream() | ||
.filter(Objects::nonNull) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
Oops, something went wrong.