Skip to content

Commit

Permalink
Merge branch 'eclipse:master' into department-search
Browse files Browse the repository at this point in the history
  • Loading branch information
KoukiHama authored Jul 21, 2022
2 parents e2ef4a5 + 7f9528d commit 0fe8e43
Show file tree
Hide file tree
Showing 63 changed files with 1,275 additions and 265 deletions.
35 changes: 18 additions & 17 deletions .github/workflows/githubactions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,46 @@ env:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- uses: actions/checkout@v3

- name: Setup CouchDB
uses: iamssen/couchdb-github-action@master
with:
couchdb-version: '3.1'

- name: Update properties with DB credentials
run: |
sudo apt-get update -qq
sudo sed -i 's/^couchdb.user\s*=/& '${COUCHDB_USER}'/' build-configuration/test-resources/couchdb-test.properties
sudo sed -i 's/^couchdb.password\s*=/& '${COUCHDB_PASSWORD}'/' build-configuration/test-resources/couchdb-test.properties
sudo mkdir /etc/sw360
sudo mkdir -p /etc/sw360
sudo cp ./scripts/sw360BackendRestDockerConfig/etc_sw360/couchdb-test.properties /etc/sw360/
- name: Set up JDK 11
run: |
wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo tee /usr/share/keyrings/adoptium.asc
echo "deb [signed-by=/usr/share/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | sudo tee /etc/apt/sources.list.d/adoptium.list
- name: Prepare build environment
run: |
sudo apt-get update -qq
sudo DEBIAN_FRONTEND=noninteractive apt-get install -yq python3-pip build-essential libboost-dev libboost-test-dev libboost-program-options-dev libevent-dev automake libtool flex bison pkg-config libssl-dev git temurin-11-jdk maven
pip install mkdocs mkdocs-material
- name: Verify license headers
run: |
chmod +x .github/testForLicenseHeaders.sh
bash .github/testForLicenseHeaders.sh
- name: Install Thrift and mkdocs
- name: Install Thrift
run: |
sudo apt-get update
sudo apt-get install python3
sudo apt-get install python3-pip
sudo pip3 install mkdocs
sudo pip3 install mkdocs-material
chmod +x scripts/install-thrift.sh
bash scripts/install-thrift.sh --no-cleanup
- name: Build SW360
run: mvn clean package --no-transfer-progress -P deploy -Dhelp-docs=true -Dbase.deploy.dir=. -Dliferay.deploy.dir=/home/runner/work/sw360/sw360/deploy -Dbackend.deploy.dir=/home/runner/work/sw360/sw360/webapps -Drest.deploy.dir=/home/runner/work/sw360/sw360/webapps -DRunComponentVisibilityRestrictionTest=false -DRunPrivateProjectAccessTest=false
run: mvn clean package --no-transfer-progress -P deploy -Dhelp-docs=true -Dbase.deploy.dir=. -Dliferay.deploy.dir=${PWD}/deploy -Dbackend.deploy.dir=${PWD}/deploy/webapps -Drest.deploy.dir=${PWD}/deploy/webapps -DRunComponentVisibilityRestrictionTest=false -DRunPrivateProjectAccessTest=false

- name: Run PrivateProjectAccessTest
run: |
Expand All @@ -81,7 +82,7 @@ jobs:
- name: Create users and oauth client
run: bash scripts/sw360BackendRestDockerConfig/scripts/createUserAndOauthClient.sh

- name: Run Client Itegration Test for Rest Api
- name: Run Client Integration Test for Rest Api
run: |
cd clients
mvn clean install --no-transfer-progress -DRunRestIntegrationTest=true
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ data
config
.tmp
.env

# Gradle generated files
bin/**
gen/**
.gradletasknamecache
.gradle/
build/
bin/
tmp/**
tmp/**/*
111 changes: 59 additions & 52 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@
# SPDX-License-Identifier: EPL-2.0
#

FROM maven:3.8-eclipse-temurin-11 AS builder
FROM eclipse-temurin:11-jdk-jammy AS builder

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
# Set versiona as arguments
ARG CLUCENE_VERSION=2.1.0
ARG THRIFT_VERSION=0.16.0
ARG MAVEN_VERSION=3.8.6

# Lets get dependencies as buildkit cached
ENV SW360_DEPS_DIR=/var/cache/deps
COPY ./scripts/docker-config/download_dependencies.sh /var/tmp/deps.sh
RUN --mount=type=cache,mode=0755,target=/var/cache/deps,sharing=locked \
chmod +x /var/tmp/deps.sh \
&& /var/tmp/deps.sh

RUN --mount=type=cache,mode=0755,target=/var/cache/apt,sharing=locked \
--mount=type=cache,mode=0755,target=/var/lib/apt,sharing=locked \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
automake \
Expand All @@ -31,9 +43,13 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
pkg-config \
procps \
wget \
unzip \
zip \
&& rm -rf /var/lib/apt/lists/*

# Prepare proxy for maven
# Prepare maven from binary to avoid wrong java dependencies and proxy
RUN --mount=type=cache,mode=0755,target=/var/cache/deps \
tar -xzf "/var/cache/deps/apache-maven-$MAVEN_VERSION-bin.tar.gz" --strip-components=1 -C /usr/local
COPY scripts/docker-config/mvn-proxy-settings.xml /etc
COPY scripts/docker-config/set_proxy.sh /usr/local/bin/setup_maven_proxy
RUN chmod a+x /usr/local/bin/setup_maven_proxy
Expand All @@ -42,15 +58,15 @@ RUN chmod a+x /usr/local/bin/setup_maven_proxy
# Thrift
FROM builder AS thriftbuild

ARG THRIFT_VERSION=0.14.0
ARG BASEDIR="/build"
ARG THRIFT_VERSION=0.16.0

COPY deps/thrift-*.tar.gz /deps/
COPY ./scripts/docker-config/install_scripts/build_thrift.sh build_thrift.sh
COPY ./scripts/install-thrift.sh build_thrift.sh

RUN --mount=type=tmpfs,target=/build \
tar -xzf "deps/thrift-$THRIFT_VERSION.tar.gz" --strip-components=1 -C /build \
&& ./build_thrift.sh \
&& rm -rf /deps
--mount=type=cache,mode=0755,target=/var/cache/deps,sharing=locked \
tar -xzf "/var/cache/deps/thrift-$THRIFT_VERSION.tar.gz" --strip-components=1 -C /build \
&& ./build_thrift.sh --tarball

#--------------------------------------------------------------------------------------------------
# Couchdb-Lucene
Expand All @@ -60,66 +76,59 @@ ARG CLUCENE_VERSION=2.1.0

WORKDIR /build

COPY deps/couchdb* /deps/
COPY ./scripts/docker-config/couchdb-lucene.ini /deps

# Prepare source code
RUN --mount=type=tmpfs,target=/build \
--mount=type=cache,target=/root/.m2,rw,sharing=locked \
tar -C /build -xvf /deps/couchdb-lucene-$CLUCENE_VERSION.tar.gz --strip-components=1 \
&& patch -p1 < /deps/couchdb-lucene.patch \
&& cp /deps/couchdb-lucene.ini ./src/main/resources/couchdb-lucene.ini \
COPY ./scripts/docker-config/couchdb-lucene.ini /var/tmp/couchdb-lucene.ini
COPY ./scripts/patches/couchdb-lucene.patch /var/tmp/couchdb-lucene.patch

# Build CLucene
RUN --mount=type=cache,mode=0755,target=/var/cache/deps,sharing=locked \
--mount=type=tmpfs,target=/build \
--mount=type=cache,mode=0755,target=/root/.m2,rw,sharing=locked \
tar -C /build -xf /var/cache/deps/couchdb-lucene-$CLUCENE_VERSION.tar.gz --strip-components=1 \
&& patch -p1 < /var/tmp/couchdb-lucene.patch \
&& cp /var/tmp/couchdb-lucene.ini src/main/resources/couchdb-lucene.ini \
&& setup_maven_proxy \
&& mvn dependency:go-offline \
&& mvn dependency:go-offline -B \
&& mvn install war:war \
&& cp ./target/*.war /couchdb-lucene.war \
&& rm -rf /deps
&& cp ./target/*.war /couchdb-lucene.war

#--------------------------------------------------------------------------------------------------
# SW360
# We build sw360 and create real image after everything is ready
# So when decide to use as development, only this last stage
# is triggered by buildkit images

FROM builder AS sw360build

# Copy thrft from builder
COPY --from=thriftbuild /thrift-bin.tar.gz /deps/
RUN tar xzf /deps/thrift-bin.tar.gz -C /
FROM thriftbuild AS sw360build

# Install mkdocs to generate documentation
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
mkdocs \
RUN --mount=type=cache,mode=0755,target=/var/cache/apt,sharing=locked \
--mount=type=cache,mode=0755,target=/var/lib/apt,sharing=locked \
apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -qq -y --no-install-recommends \
python3-pip \
python3-wheel \
&& rm -rf /var/lib/apt/lists/* \
&& pip install mkdocs-material

# Copy the exported sw360 directory
COPY deps/sw360.tar /deps/
# Copy the sw360 directory
COPY . /build/sw360

RUN --mount=type=tmpfs,target=/build \
--mount=type=cache,target=/root/.m2,rw,sharing=locked \
tar -C /build -xf /deps/sw360.tar \
&& cd /build/sw360 \
RUN --mount=type=cache,mode=0755,target=/root/.m2,rw,sharing=locked \
cd /build/sw360 \
&& setup_maven_proxy \
&& mvn package \
&& mvn clean package \
-P deploy -Dtest=org.eclipse.sw360.rest.resourceserver.restdocs.* \
-DfailIfNoTests=false \
-Dbase.deploy.dir=. \
-Dliferay.deploy.dir=/sw360_deploy \
-Dbackend.deploy.dir=/sw360_tomcat_webapps \
-Drest.deploy.dir=/sw360_tomcat_webapps \
-Dhelp-docs=true \
&& rm -rf /deps
-Dhelp-docs=true

#--------------------------------------------------------------------------------------------------
# Runtime image
# We need use JDK, JRE is not enough as Liferay do runtime changes and require javac
FROM eclipse-temurin:11-jdk-focal
FROM eclipse-temurin:11-jdk-jammy

WORKDIR /app/

Expand All @@ -129,9 +138,10 @@ ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update \
RUN --mount=type=cache,mode=0755,target=/var/cache/apt,sharing=locked \
--mount=type=cache,mode=0755,target=/var/lib/apt,sharing=locked \
--mount=type=cache,mode=0755,target=/var/cache/deps,sharing=locked \
apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates \
curl \
Expand All @@ -151,9 +161,6 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
zip \
&& rm -rf /var/lib/apt/lists/*

COPY deps/jars/* /deps/jars/
COPY deps/liferay-ce* /deps/

COPY --from=thriftbuild /thrift-bin.tar.gz .
RUN tar xzf thrift-bin.tar.gz -C / \
&& rm thrift-bin.tar.gz
Expand Down Expand Up @@ -182,12 +189,12 @@ RUN echo "$USERNAME ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \

# Unpack liferay as sw360 and link current tomcat version
# to tomcat to make future proof updates
RUN mkdir sw360 \
&& tar xzf /deps/$LIFERAY_SOURCE -C $USERNAME --strip-components=1 \
&& cp /deps/jars/* sw360/deploy \
RUN --mount=type=cache,mode=0755,target=/var/cache/deps,sharing=locked \
mkdir sw360 \
&& tar xzf /var/cache/deps/$LIFERAY_SOURCE -C $USERNAME --strip-components=1 \
&& cp /var/cache/deps/jars/* sw360/deploy \
&& chown -R $USERNAME:$USERNAME sw360 \
&& ln -s /app/sw360/tomcat-* /app/sw360/tomcat \
&& rm -rf /deps
&& ln -s /app/sw360/tomcat-* /app/sw360/tomcat

COPY --chown=$USERNAME:$USERNAME --from=sw360build /sw360_deploy/* /app/sw360/deploy
COPY --chown=$USERNAME:$USERNAME --from=sw360build /sw360_tomcat_webapps/* /app/sw360/tomcat/webapps/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public class UserRepository extends SummaryAwareRepository<User> {
" emit(doc.restApiTokens[i].token, doc._id)" +
" }" +
"}";
private static final String BYOIDCCLIENTID = "function(doc) { if (doc.type == 'user') " +
" for (var i in doc.oidcClientInfos) {" +
" emit(i, doc._id)" +
" }" +
"}";
private static final String BYEMAIL = "function(doc) { " +
" if (doc.type == 'user') {" +
" emit(doc.email, doc._id); " +
Expand Down Expand Up @@ -87,6 +92,7 @@ public UserRepository(DatabaseConnectorCloudant databaseConnector) {
views.put("all", createMapReduce(ALL, null));
views.put("byExternalId", createMapReduce(BYEXTERNALID, null));
views.put("byApiToken", createMapReduce(BYAPITOKEN, null));
views.put("byOidcClientId", createMapReduce(BYOIDCCLIENTID, null));
views.put("byEmail", createMapReduce(BYEMAIL, null));
views.put("userDepartments", createMapReduce(USERS_ALL_DEPARTMENT_VIEW, null));
views.put("userEmails", createMapReduce(USERS_ALL_EMAIL_VIEW, null));
Expand Down Expand Up @@ -243,4 +249,9 @@ private Map<PaginationData, List<User>> queryViewWithPagination(PaginationData p
result.put(pageData, users);
return result;
}

public User getByOidcClientId(String clientId) {
final Set<String> userIds = queryForIdsAsValue("byOidcClientId", clientId);
return getUserFromIds(userIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@

import static com.google.common.base.Strings.isNullOrEmpty;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseRepositoryCloudantClient;
Expand All @@ -31,13 +34,21 @@ public class VendorRepository extends DatabaseRepositoryCloudantClient<Vendor> {

private static final String ALL = "function(doc) { if (doc.type == 'vendor') emit(null, doc._id) }";

private static final String BY_FULL_NAME = "function(doc) { if (doc.type == 'vendor' && doc.fullname != null) emit(doc.fullname.toLowerCase(), doc._id) }";

public VendorRepository(DatabaseConnectorCloudant db) {
super(db, Vendor.class);
Map<String, MapReduce> views = new HashMap<String, MapReduce>();
views.put("all", createMapReduce(ALL, null));
views.put("vendorbyfullname", createMapReduce(BY_FULL_NAME, null));
initStandardDesignDocument(views, db);
}

public List<Vendor> searchByFullname(String fullname) {
List<Vendor> vendorsMatchingFullname = new ArrayList<Vendor>(get(queryForIdsAsValue("vendorbyfullname", fullname)));
return vendorsMatchingFullname;
}

public void fillVendor(Component component) {
if (component.isSetDefaultVendorId()) {
final String vendorId = component.getDefaultVendorId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class CLIParser extends AbstractCLIParser {
private static final String COPYRIGHTS_XPATH = "/ComponentLicenseInformation/Copyright/Content";
private static final String LICENSES_XPATH = "/ComponentLicenseInformation/License";
private static final String OBLIGATIONS_XPATH = "/ComponentLicenseInformation/Obligation";
private static final String ASSESSMENT_SUMMARY_XPATH = "/ComponentLicenseInformation/AssessmentSummary";
private static final String CLI_ROOT_ELEMENT_NAME = "ComponentLicenseInformation";
private static final String CLI_ROOT_XPATH = "/ComponentLicenseInformation";
private static final String CLI_ROOT_ELEMENT_NAMESPACE = null;
Expand Down Expand Up @@ -130,6 +131,7 @@ private <T> List<LicenseInfoParsingResult> getLicenseInfosDelegated(Attachment a
}

licenseInfo.setLicenseNamesWithTexts(getLicenseNameWithTexts(doc, includeFilesHash));
licenseInfo.setAssessmentSummary(getAssessmentSummary(doc));

licenseInfo.setSha1Hash(getSha1Hash(doc));
licenseInfo.setComponentName(getComponent(doc));
Expand All @@ -154,6 +156,23 @@ private Set<LicenseNameWithText> getLicenseNameWithTexts(Document doc, boolean i
return nodeListToLicenseNamesWithTextsSet(licenseNodes, includeFilesHash);
}

private Map<String, String> getAssessmentSummary(Document doc) throws XPathExpressionException {
NodeList assessmentSummaryList = getNodeListByXpath(doc, ASSESSMENT_SUMMARY_XPATH);
Map<String, String> assessmentSummaryMap = new HashMap<String, String>();
if (assessmentSummaryList.getLength() == 1) {
Node node = assessmentSummaryList.item(0);
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
String nodeName = childNodes.item(i).getNodeName();
String textContent = childNodes.item(i).getTextContent();
assessmentSummaryMap.put(nodeName, textContent);
}
} else {
log.error("AssessmentSummary not found in CLI!");
}
return assessmentSummaryMap;
}

private Set<String> getCopyrights(Document doc) throws XPathExpressionException {
NodeList copyrightNodes = getNodeListByXpath(doc, COPYRIGHTS_XPATH);
return nodeListToStringSet(copyrightNodes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public User getByApiToken(String token) throws TException {
return db.getByApiToken(token);
}


@Override
public User getByOidcClientId(String clientId) throws TException {
assertNotEmpty(clientId);
return db.getByOidcClientId(clientId);
}

@Override
public List<User> searchUsers(String searchText) {
return db.searchUsers(searchText);
Expand Down
Loading

0 comments on commit 0fe8e43

Please sign in to comment.