-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(java): maven-changelog-plugin
- Loading branch information
1 parent
e37db17
commit 922cfc8
Showing
28 changed files
with
10,317 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
Java/maven-changelog-plugin-ChangeLogHandler_114/Dockerfile
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,18 @@ | ||
FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-changelog-plugin | ||
|
||
ENV TZ=Asia/Seoul | ||
|
||
COPY ./metadata.json . | ||
COPY ./npe.json . | ||
COPY ./buggy.java /tmp/buggy.java | ||
RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ | ||
&& export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ | ||
&& export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ | ||
&& mv /tmp/buggy.java $BUGGY_PATH \ | ||
&& echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json | ||
|
||
RUN git init . && git add -A | ||
|
||
RUN $(cat metadata.json | jq -r ".buildCommand") | ||
|
||
RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi |
230 changes: 230 additions & 0 deletions
230
Java/maven-changelog-plugin-ChangeLogHandler_114/buggy.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,230 @@ | ||
package org.apache.maven.plugin.changelog; | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
import org.apache.maven.scm.ChangeFile; | ||
import org.apache.maven.scm.ChangeSet; | ||
import org.apache.maven.scm.ScmTag; | ||
import org.apache.maven.scm.command.changelog.ChangeLogSet; | ||
import org.xml.sax.Attributes; | ||
import org.xml.sax.SAXException; | ||
import org.xml.sax.helpers.DefaultHandler; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Collection; | ||
import java.util.Date; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.TimeZone; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Change log generated xml parser. SAXParser listener for processing a previously generated xml into several | ||
* change log sets. | ||
* | ||
* @version $Id$ | ||
*/ | ||
public class ChangeLogHandler | ||
extends DefaultHandler | ||
{ | ||
// Use the same time zone offset when reading and adding times | ||
// It doesn't matter which one we use, as long we always use the same one | ||
private static final String TIMEZONE_STRING = "GMT-00:00"; | ||
|
||
private static final TimeZone TIMEZONE = TimeZone.getTimeZone( TIMEZONE_STRING ); | ||
|
||
private Collection<ChangeLogSet> changeSets; | ||
|
||
private String bufData = ""; | ||
|
||
private ChangeFile bufFile; | ||
|
||
private ChangeSet bufEntry; | ||
|
||
private List<ChangeSet> bufEntries; | ||
|
||
private ChangeLogSet bufSet; | ||
|
||
private String currentPattern; | ||
|
||
private final Pattern nameRegex = Pattern.compile( " \\(from [^:]+:\\d+\\)" ); | ||
|
||
/** | ||
* contructor | ||
* | ||
* @param changeSets collection object to store all change sets found within the xml document | ||
*/ | ||
public ChangeLogHandler( Collection<ChangeLogSet> changeSets ) | ||
{ | ||
this.changeSets = changeSets; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public void characters( char[] ch, int start, int length ) | ||
throws SAXException | ||
{ | ||
bufData += new String( ch, start, length ); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
/** | ||
* {@inheritDoc } | ||
*/ | ||
public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException { | ||
if ("changeset".equals(qName)) { | ||
changeSets.add(bufSet); | ||
} | ||
if ("changelog-entry".equals(qName)) { | ||
bufEntries.add(bufEntry); | ||
} | ||
if ("file".equals(qName)) { | ||
bufEntry.addFile(bufFile); | ||
} else if ("date".equals(qName)) { | ||
try { | ||
long ms = 0; | ||
{ | ||
ms = /* NPEX_NULL_EXP */ | ||
bufEntry.getDate().getTime(); | ||
} | ||
bufEntry.setDate(new java.util.Date(ms + new java.text.SimpleDateFormat(currentPattern).parse(bufData).getTime())); | ||
} catch (java.text.ParseException e) { | ||
throw new org.xml.sax.SAXException(e); | ||
} | ||
} else if ("time".equals(qName)) { | ||
try { | ||
long ms = 0; | ||
if (bufEntry.getDate() != null) { | ||
ms = bufEntry.getDate().getTime(); | ||
} | ||
java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat(currentPattern); | ||
// MCHANGELOG-68 Adjust for time zone when parsing the time | ||
simpleDateFormat.setTimeZone(org.apache.maven.plugin.changelog.ChangeLogHandler.TIMEZONE); | ||
// Adjust for time zone when adding up the milliseconds | ||
bufEntry.setDate(new java.util.Date((ms + simpleDateFormat.parse(bufData).getTime()) + org.apache.maven.plugin.changelog.ChangeLogHandler.TIMEZONE.getRawOffset())); | ||
} catch (java.text.ParseException e) { | ||
throw new org.xml.sax.SAXException(e); | ||
} | ||
} else if ("author".equals(qName)) { | ||
bufEntry.setAuthor(bufData); | ||
} else if ("msg".equals(qName)) { | ||
bufEntry.setComment(bufData); | ||
} | ||
if ("revision".equals(qName)) { | ||
bufFile.setRevision(bufData); | ||
} else if ("name".equals(qName)) { | ||
bufFile.setName(nameRegex.matcher(bufData).replaceFirst("")); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public void startElement( String uri, String localName, String qName, Attributes attributes ) | ||
throws SAXException | ||
{ | ||
bufData = ""; | ||
|
||
if ( "file".equals( qName ) ) | ||
{ | ||
bufFile = new ChangeFile( "" ); | ||
} | ||
else if ( "changelog-entry".equals( qName ) ) | ||
{ | ||
bufEntry = new ChangeSet(); | ||
} | ||
else if ( "date".equals( qName ) ) | ||
{ | ||
currentPattern = attributes.getValue( "pattern" ); | ||
if ( currentPattern == null ) | ||
{ | ||
currentPattern = "yyyy-MM-dd"; | ||
} | ||
} | ||
else if ( "time".equals( qName ) ) | ||
{ | ||
currentPattern = attributes.getValue( "pattern" ); | ||
if ( currentPattern == null ) | ||
{ | ||
currentPattern = "HH:mm:ss"; | ||
} | ||
} | ||
else if ( "changeset".equals( qName ) ) | ||
{ | ||
bufEntries = new LinkedList<ChangeSet>(); | ||
|
||
currentPattern = attributes.getValue( "datePattern" ); | ||
if ( currentPattern == null ) | ||
{ | ||
currentPattern = "yyyy-MM-dd"; | ||
} | ||
|
||
SimpleDateFormat formatter = new SimpleDateFormat( currentPattern ); | ||
|
||
String start = attributes.getValue( "start" ); | ||
|
||
String end = attributes.getValue( "end" ); | ||
|
||
Date startDate = null; | ||
|
||
Date endDate = null; | ||
|
||
if ( start != null ) | ||
{ | ||
try | ||
{ | ||
startDate = formatter.parse( start ); | ||
} | ||
catch ( ParseException e ) | ||
{ | ||
throw new SAXException( "Can't parse start date '" + start + "'.", e ); | ||
} | ||
} | ||
|
||
if ( end != null ) | ||
{ | ||
try | ||
{ | ||
endDate = formatter.parse( end ); | ||
} | ||
catch ( ParseException e ) | ||
{ | ||
throw new SAXException( "Can't parse end date '" + end + "'.", e ); | ||
} | ||
} | ||
|
||
bufSet = new ChangeLogSet( bufEntries, startDate, endDate ); | ||
String startVersion = attributes.getValue( "startVersion" ); | ||
if ( startVersion != null ) | ||
{ | ||
bufSet.setStartVersion( new ScmTag( startVersion ) ); | ||
} | ||
String endVersion = attributes.getValue( "endVersion" ); | ||
if ( endVersion != null ) | ||
{ | ||
bufSet.setEndVersion( new ScmTag( endVersion ) ); | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Java/maven-changelog-plugin-ChangeLogHandler_114/metadata.json
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,21 @@ | ||
{ | ||
"language": "java", | ||
"id": "maven-changelog-plugin-ChangeLogHandler_114", | ||
"buggyPath": ".", | ||
"referencePath": null, | ||
"buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", | ||
"testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", | ||
"categories": [ | ||
"safety", | ||
"npe" | ||
], | ||
"npe": { | ||
"filepath": "src/main/java/org/apache/maven/plugin/changelog/ChangeLogHandler.java", | ||
"line": 109, | ||
"npe_method": "endElement", | ||
"deref_field": "getDate", | ||
"npe_class": "ChangeLogHandler", | ||
"repo": "maven-changelog-plugin", | ||
"bug_id": "ChangeLogHandler_114" | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"filepath": "src/main/java/org/apache/maven/plugin/changelog/ChangeLogHandler.java", | ||
"line": 109, | ||
"npe_method": "endElement", | ||
"deref_field": "getDate", | ||
"npe_class": "ChangeLogHandler" | ||
} |
18 changes: 18 additions & 0 deletions
18
Java/maven-changelog-plugin-ChangeLogHandler_130/Dockerfile
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,18 @@ | ||
FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-changelog-plugin | ||
|
||
ENV TZ=Asia/Seoul | ||
|
||
COPY ./metadata.json . | ||
COPY ./npe.json . | ||
COPY ./buggy.java /tmp/buggy.java | ||
RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ | ||
&& export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ | ||
&& export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ | ||
&& mv /tmp/buggy.java $BUGGY_PATH \ | ||
&& echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json | ||
|
||
RUN git init . && git add -A | ||
|
||
RUN $(cat metadata.json | jq -r ".buildCommand") | ||
|
||
RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi |
Oops, something went wrong.