Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
1,338 additions
and
1,771 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
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
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
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
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
70 changes: 70 additions & 0 deletions
70
...e/src/main/java/com/synopsys/integration/detectable/detectables/bazel/BazelWorkspace.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,70 @@ | ||
/** | ||
* detectable | ||
* | ||
* Copyright (c) 2019 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.bazel; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class BazelWorkspace { | ||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
private final File workspaceFile; | ||
|
||
public BazelWorkspace(final File workspaceFile) { | ||
this.workspaceFile = workspaceFile; | ||
} | ||
|
||
public WorkspaceRule getDependencyRule() { | ||
final List<String> workspaceFileLines; | ||
try { | ||
// Assumes ascii or UTF-8, like other detectors | ||
workspaceFileLines = FileUtils.readLines(workspaceFile, StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
logger.debug(String.format("Unable to parse dependency rule from %s: %s", workspaceFile.getAbsolutePath(), e.getMessage())); | ||
return WorkspaceRule.UNKNOWN; | ||
} | ||
final WorkspaceRule dependencyRule = parseDependencyRuleFromWorkspaceFileLines(workspaceFileLines); | ||
return dependencyRule; | ||
} | ||
|
||
@Nullable | ||
public WorkspaceRule parseDependencyRuleFromWorkspaceFileLines(final List<String> workspaceFileLines) { | ||
for (final String workspaceFileLine : workspaceFileLines) { | ||
for (final WorkspaceRule workspaceRuleCandidate : WorkspaceRule.values()) { | ||
if (workspaceFileLine.matches(String.format("^\\s*%s\\s*\\(", workspaceRuleCandidate.getName()))) { | ||
final WorkspaceRule parsedDependencyRule = workspaceRuleCandidate; | ||
logger.debug(String.format("Found workspace dependency rule: %s", parsedDependencyRule.getName())); | ||
return parsedDependencyRule; | ||
} | ||
} | ||
} | ||
logger.debug("Unable to derive dependency rule from WORKSPACE file"); | ||
return WorkspaceRule.UNKNOWN; | ||
} | ||
} |
Oops, something went wrong.