Skip to content

Commit

Permalink
fix: reinstate advertising all-sub-projects when only scanning one (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyegupov authored May 20, 2019
1 parent 19b56c4 commit 2dff45e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
15 changes: 8 additions & 7 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface PluginMetadata {
meta?: {
// If we don't return the results for all dependency roots (subprojects),
// still record their names to warn the user about them not being scanned
allDepRootNames?: string[];
allSubProjectNames?: string[];
};
}

Expand Down Expand Up @@ -120,9 +120,9 @@ export async function inspect(root, targetFile, options?: SingleRootInspectOptio
};
}
const depTreeAndDepRootNames = await getAllDepsOneProject(root, targetFile, options, subProject);
if (depTreeAndDepRootNames.allDepRootNames) {
if (depTreeAndDepRootNames.allSubProjectNames) {
plugin.meta = plugin.meta || {};
plugin.meta.allDepRootNames = depTreeAndDepRootNames.allDepRootNames;
plugin.meta.allSubProjectNames = depTreeAndDepRootNames.allSubProjectNames;
}
return {
plugin,
Expand All @@ -142,6 +142,7 @@ function targetFileFilteredForCompatibility(targetFile: string): string | undefi
interface JsonDepsScriptResult {
defaultProject: string;
projects: ProjectsDict;
allSubProjectNames: string[];
}

interface ProjectsDict {
Expand Down Expand Up @@ -171,15 +172,15 @@ function extractJsonFromScriptOutput(stdoutText: string): JsonDepsScriptResult {
}

async function getAllDepsOneProject(root, targetFile, options, subProject):
Promise<{depTree: DepTree, allDepRootNames: string[]}> {
Promise<{depTree: DepTree, allSubProjectNames: string[]}> {
const packageName = path.basename(root);
const allProjectDeps = await getAllDeps(root, targetFile, options);
const allDepRootNames = Object.keys(allProjectDeps.projects);
const allSubProjectNames = allProjectDeps.allSubProjectNames;
let depDict = {} as DepDict;
if (subProject) {
return {
depTree: getDepsSubProject(root, subProject, allProjectDeps),
allDepRootNames,
allSubProjectNames,
};
}

Expand All @@ -194,7 +195,7 @@ async function getAllDepsOneProject(root, targetFile, options, subProject):
version: '0.0.0',
packageFormatVersion,
},
allDepRootNames,
allSubProjectNames,
};
}

Expand Down
7 changes: 6 additions & 1 deletion lib/init.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import groovy.json.JsonOutput
// interface JsonDepsScriptResult {
// defaultProject: string;
// projects: ProjectsDict;
// allSubProjectNames: string[];
// }
// interface ProjectsDict {
// [project: string]: GradleProjectInfo;
Expand Down Expand Up @@ -71,7 +72,11 @@ allprojects { everyProj ->
doLast { task ->
def projectsDict = [:]
def defaultProjectName = task.project.name
def result = ['defaultProject': defaultProjectName, 'projects': projectsDict]
def result = [
'defaultProject': defaultProjectName,
'projects': projectsDict,
'allSubProjectNames': allprojects.collect { it.name }
]
if (!snykMergedDepsConfExecuted) {

def shouldScanProject = {
Expand Down
18 changes: 9 additions & 9 deletions test/system/multi-module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('multi-project, explicitly targeting a subproject build file', async (t) =>
path.join(fixtureDir('multi-project'), 'subproj', 'build.gradle'));
t.equals(result.package.name, '.',
'root project is "."');
t.deepEqual(result.plugin.meta!.allDepRootNames, ['subproj']);
t.deepEqual(result.plugin.meta!.allSubProjectNames, ['subproj']);

t.equal(result.package
.dependencies!['com.android.tools.build:builder']
Expand All @@ -26,7 +26,7 @@ test('multi-project, ran from root, targeting subproj', async (t) => {
'subproj/build.gradle');
t.equals(result.package.name, 'multi-project',
'root project is "multi-project"');
t.deepEqual(result.plugin.meta!.allDepRootNames, ['subproj']);
t.deepEqual(result.plugin.meta!.allSubProjectNames, ['subproj']);

t.equal(result.package
.dependencies!['com.android.tools.build:builder']
Expand All @@ -44,7 +44,7 @@ test('multi-project, ran from a subproject directory', async (t) => {
'build.gradle');
t.equals(result.package.name, 'subproj',
'root project is "subproj"');
t.deepEqual(result.plugin.meta!.allDepRootNames, ['subproj']);
t.deepEqual(result.plugin.meta!.allSubProjectNames, ['subproj']);

t.equal(result.package
.dependencies!['com.android.tools.build:builder']
Expand All @@ -65,7 +65,7 @@ test('multi-project: only sub-project has deps and they are returned', async (t)
options);
t.match(result.package.name, '/subproj',
'sub project name is included in the root pkg name');
t.deepEqual(result.plugin.meta!.allDepRootNames, ['subproj']);
t.deepEqual(result.plugin.meta!.allSubProjectNames, ['root-proj', 'subproj']);

t.equal(result.package
.dependencies!['com.android.tools.build:builder']
Expand All @@ -82,7 +82,7 @@ test('multi-project: only sub-project has deps, none returned for main', async (
path.join(fixtureDir('multi-project'), 'build.gradle'));
t.match(result.package.name, '.',
'returned project name is not sub-project');
t.deepEqual(result.plugin.meta!.allDepRootNames, ['root-proj']);
t.deepEqual(result.plugin.meta!.allSubProjectNames, ['root-proj', 'subproj']);
t.notOk(result.package.dependencies);
});

Expand All @@ -91,7 +91,7 @@ test('multi-project: using gradle via wrapper', async (t) => {
path.join(fixtureDir('multi-project gradle wrapper'), 'build.gradle'));
t.match(result.package.name, '.',
'returned project name is not sub-project');
t.deepEqual(result.plugin.meta!.allDepRootNames, ['root-proj']);
t.deepEqual(result.plugin.meta!.allSubProjectNames, ['root-proj', 'subproj']);
t.notOk(result.package.dependencies);
});

Expand All @@ -110,7 +110,7 @@ test('multi-project: only sub-project has deps and they are returned space needs
path.join(fixtureDir('multi-project'), 'build.gradle'),
options);

t.deepEqual(result.plugin.meta!.allDepRootNames, ['subproj']);
t.deepEqual(result.plugin.meta!.allSubProjectNames, ['root-proj', 'subproj']);

t.match(result.package.name, '/subproj',
'sub project name is included in the root pkg name');
Expand Down Expand Up @@ -175,7 +175,7 @@ test('multi-project-some-unscannable: gradle-sub-project for a good subproject w
path.join(fixtureDir('multi-project-some-unscannable'), 'build.gradle'),
options);

t.deepEqual(result.plugin.meta!.allDepRootNames, ['subproj']);
t.deepEqual(result.plugin.meta!.allSubProjectNames, ['root-proj', 'subproj', 'subproj-fail']);

t.match(result.package.name, '/subproj',
'sub project name is included in the root pkg name');
Expand Down Expand Up @@ -247,7 +247,7 @@ test('multi-project-dependency-cycle: scanning the main project works fine', asy
path.join(fixtureDir('multi-project-dependency-cycle'), 'build.gradle'),
{});
t.equal(result.package.name, '.', 'root project name is "."');
t.deepEqual(result.plugin.meta!.allDepRootNames, ['root-proj']);
t.deepEqual(result.plugin.meta!.allSubProjectNames, ['root-proj', 'subproj']);

t.equal(result.package
.dependencies!['com.github.jitpack:subproj']
Expand Down

0 comments on commit 2dff45e

Please sign in to comment.