Skip to content

Commit e405fce

Browse files
committed
C# sln 파일 지정 기능 추가
1 parent df9e4c5 commit e405fce

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

src/main/java/com/samsungsds/analyst/code/main/App.java

+2
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ private void runComplexityForCSharp(CliParser cli) {
414414

415415
codeAnalysis.addOption("-dir", cli.getProjectBaseDir());
416416

417+
codeAnalysis.addOption("sln", cli.getSrc());
418+
417419
codeAnalysis.run(cli.getInstanceKey());
418420

419421
observerManager.notifyObservers(ProgressEvent.COMPLEXITY_COMPLETE);

src/main/java/com/samsungsds/analyst/code/main/AppForSonarAnalysisForCSharp.java

+15
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ private void runScannerForMSBuild(MSBuildEnv env, String scannerDirectory, List<
110110
}
111111

112112
private void runMSBuild(MSBuildEnv env, String projectBaseDir) {
113+
projectBaseDir = getSolutionFile(projectBaseDir);
114+
113115
List<String> command = new ArrayList<>();
114116
if (env == MSBuildEnv.DOT_NET_FRAMEWORK) {
115117
command.add("MSBuild.exe");
@@ -124,6 +126,19 @@ private void runMSBuild(MSBuildEnv env, String projectBaseDir) {
124126
runProcessBuilder(command, projectBaseDir);
125127
}
126128

129+
private String getSolutionFile(String projectBaseDir) {
130+
if (".".equals(cli.getSrc())) {
131+
return projectBaseDir;
132+
}
133+
134+
File sln = new File(projectBaseDir, cli.getSrc());
135+
if (sln.exists()) {
136+
return sln.getAbsolutePath();
137+
} else {
138+
throw new IllegalArgumentException("sln file not found : " + sln.getAbsolutePath());
139+
}
140+
}
141+
127142
private void runProcessBuilder(List<String> command, String workingDirectory) {
128143
ProcessBuilder builder;
129144
builder = new ProcessBuilder(command);

src/main/java/com/samsungsds/analyst/code/main/Version.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class Version {
7171
// 2.10.6 : JavaScript ESLint 여러 src 처리 오류, Python pip Linux 경로 오류, Python radon 관련 오류 수정
7272
// PMD CPD 중복 체크 기능 다른 언어 적용, PMD CPD 충돌(w/ SonarQube)으로 인한 오류 수정,
7373
// Linux Node 설치 처리 오류 수정, C# CK Metrics exclude/include 오류 수정
74-
// 2.10.7 : Python 경로지정 기능 추가("python" 시스템 속성), Unused 처리 소스 인코딩 지정 추가
74+
// 2.10.7 : Python 경로지정 기능 추가("python" 시스템 속성), Unused 처리 소스 인코딩 지정 추가, C# sln 파일 지정 기능
7575
// --------------------------------------------------
7676
public static final String CODE_ANALYST = "2.10.7";
7777
public static final String DOCUMENT_VERSION = "2.9";

src/main/java/com/samsungsds/analyst/code/main/cli/CliParseProcessorForCSharp.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public void setOptions(CliParser cliParser, Options options) {
4848

4949
options.addOption("h", "help", false, "show help.");
5050
options.addOption("p", "project", true, "specify project base directory. (default: \".\")");
51-
options.addOption("s", "src", true, "specify source directories with comma separated. (default: \"${project}" + File.separator + getDefaultSrcOption() + "\")");
51+
options.addOption("s", "src", true, "specify '*.sln' file in project directory. (default: 'sln' file in \"${project}\" directory. " +
52+
"However, there should be only 1 'sln' file in that directory.)");
5253

5354
options.addOption("d", "debug", false, "debug mode.");
5455
options.addOption("e", "encoding", true, "encoding of the source code. (default: UTF-8)");

src/main/java/com/samsungsds/analyst/code/roslyn/codemetrics/CodeAnalysisLauncher.java

+22-7
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ public class CodeAnalysisLauncher implements ComplexityAnalysis {
3131
private final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();;
3232
private String solutionDirectory = null;
3333

34+
private String slnFilename = ".";
35+
3436
@Override
3537
public void addOption(String option, String value) {
3638
if (option.equals("-dir")) {
3739
solutionDirectory = value;
40+
} else if (option.equals("sln")) {
41+
slnFilename = value;
3842
}
3943
}
4044

@@ -137,14 +141,25 @@ private String installCodeAnalysisAndGetPath() {
137141
private String findSolutionFile(String directory) {
138142
File dir = new File(directory);
139143

140-
File[] list = dir.listFiles((sub, name) -> {
141-
return name.endsWith(".sln");
142-
});
144+
if (".".equals(slnFilename)) {
143145

144-
if (list.length == 0) {
145-
throw new IllegalStateException("Solution(*.sln) not found in " + directory);
146-
}
146+
File[] list = dir.listFiles((sub, name) -> {
147+
return name.endsWith(".sln");
148+
});
149+
150+
if (list.length == 0) {
151+
throw new IllegalStateException("Solution(*.sln) not found in " + directory);
152+
}
147153

148-
return list[0].getName();
154+
return list[0].getName();
155+
} else {
156+
File sln = new File(dir, slnFilename);
157+
158+
if (sln.exists()) {
159+
return slnFilename;
160+
} else {
161+
throw new IllegalArgumentException("sln file not found : " + sln.getAbsolutePath());
162+
}
163+
}
149164
}
150165
}

0 commit comments

Comments
 (0)