Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
traffic-front
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangxiaoming
traffic-front
Commits
270ff261
Commit
270ff261
authored
Sep 13, 2018
by
neo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[dev] add extract commit from diff
parent
5142fba3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
0 deletions
+79
-0
ExtractCommitFromDiff.java
atms-gen/src/test/java/com/neo/ExtractCommitFromDiff.java
+79
-0
No files found.
atms-gen/src/test/java/com/neo/ExtractCommitFromDiff.java
0 → 100644
View file @
270ff261
package
com
.
neo
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.stream.Collectors
;
public
class
ExtractCommitFromDiff
{
public
static
final
String
LINE_SPLITER
=
"\r\n"
;
public
static
void
main
(
String
[]
args
)
{
try
(
BufferedReader
burReader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
new
File
(
"C:\\Users\\Neo Wang\\workspace\\atms\\atms-gen\\target\\test-classes\\diff.txt"
)))))
{
String
line
=
null
;
List
<
Diff
>
diffs
=
new
ArrayList
<>();
Diff
diff
=
null
;
while
((
line
=
burReader
.
readLine
())
!=
null
)
{
if
(
line
.
contains
(
"diff --git"
))
{
if
(
diff
!=
null
)
diffs
.
add
(
diff
);
diff
=
new
Diff
();
diff
.
fileName
=
line
.
substring
(
line
.
lastIndexOf
(
"/atms-dao"
)
+
1
,
line
.
length
());
}
else
if
(
line
.
startsWith
(
"+"
)
||
line
.
startsWith
(
"-"
))
{
if
(
line
.
startsWith
(
"++"
)
||
line
.
startsWith
(
"--"
))
continue
;
if
(
diff
==
null
)
{
System
.
out
.
println
(
line
);
throw
new
RuntimeException
(
"not init"
);
}
diff
.
diffLine
.
add
(
line
);
}
}
List
<
Diff
>
orderDiffs
=
diffs
.
stream
().
sorted
(
Comparator
.
comparing
(
Diff:
:
length
)).
collect
(
Collectors
.
toList
());
orderDiffs
.
forEach
(
m
->
{
if
(
m
.
fileName
.
contains
(
"Example"
)
)
{
System
.
out
.
println
(
m
.
fileName
);
}
});
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
static
class
Diff
{
String
fileName
;
List
<
String
>
diffLine
=
new
ArrayList
<>();
@Override
public
String
toString
()
{
StringBuilder
builder
=
new
StringBuilder
(
fileName
);
builder
.
append
(
LINE_SPLITER
);
diffLine
.
forEach
(
m
->
{
if
(!
m
.
contains
(
"*"
)
&&
!
m
.
contains
(
"deleteByPrimaryKey"
)
&&
!
m
.
contains
(
"selectByPrimaryKey"
)
&&
!
m
.
contains
(
"import"
)
&&
m
.
trim
().
length
()
>
1
)
builder
.
append
(
m
).
append
(
LINE_SPLITER
);
});
return
builder
.
toString
();
}
public
int
length
()
{
return
diffLine
.
stream
().
filter
(
m
->
{
return
!
m
.
contains
(
"*"
)
&&
!
m
.
contains
(
"deleteByPrimaryKey"
)
&&
!
m
.
contains
(
"selectByPrimaryKey"
)
&&
!
m
.
contains
(
"import"
)
&&
m
.
trim
().
length
()
>
1
;
}).
collect
(
Collectors
.
toList
()).
size
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment