Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
a6f553ac
Commit
a6f553ac
authored
Nov 19, 2018
by
fengshuonan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善maven deploy工具
parent
287d8ebb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
51 deletions
+45
-51
src/main/java/cn/stylefeng/guns/MavenDeployLocalFile.java
+45
-51
No files found.
src/main/java/cn/stylefeng/guns/MavenDeployLocalFile.java
View file @
a6f553ac
package
cn
.
stylefeng
.
guns
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.File
Writer
;
import
java.io.I
OException
;
import
java.io.File
InputStream
;
import
java.io.I
nputStreamReader
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -13,12 +14,12 @@ public class MavenDeployLocalFile {
/**
* 当前工作目录
*/
private
String
CURRENT_PATH
=
"/Users/stylefeng/
work/repository
/"
;
private
String
CURRENT_PATH
=
"/Users/stylefeng/
tmp
/"
;
/**
* 仓库的地址
*/
private
String
REPO_PATH
=
"/Users/stylefeng/
work/repository
"
;
private
String
REPO_PATH
=
"/Users/stylefeng/
tmp/share
"
;
/**
* maven的settings文件配置路径
...
...
@@ -35,8 +36,6 @@ public class MavenDeployLocalFile {
*/
private
String
REPOSITORY_URL
=
"http://172.23.2.3:8081/repository/maven-host-sedinBJ/"
;
private
List
<
String
>
finalCommands
=
new
ArrayList
<>();
/**
* 递归获取一个目录下的所有文件目录路径
*
...
...
@@ -110,7 +109,7 @@ public class MavenDeployLocalFile {
}
}
String
command
=
buildComman
(
FileType
.
POM
,
pom
);
String
command
=
buildComman
(
FileType
.
POM
,
null
,
pom
);
executeCommand
(
command
);
}
...
...
@@ -136,13 +135,8 @@ public class MavenDeployLocalFile {
}
}
if
(
pom
!=
null
)
{
String
command
=
buildComman
(
FileType
.
POM
,
pom
);
executeCommand
(
command
);
}
if
(
jar
!=
null
)
{
String
command
=
buildComman
(
FileType
.
JAR
,
jar
);
String
command
=
buildComman
(
FileType
.
JAR
,
jar
,
pom
);
executeCommand
(
command
);
}
...
...
@@ -170,9 +164,6 @@ public class MavenDeployLocalFile {
doOnlyPom
(
directory
);
}
}
//输出文件
writeToFile
(
"/Users/stylefeng/tmp/bash.sh"
,
finalCommands
);
}
/**
...
...
@@ -184,7 +175,6 @@ public class MavenDeployLocalFile {
private
void
executeCommand
(
String
command
)
{
try
{
System
.
out
.
println
(
command
);
finalCommands
.
add
(
command
);
//Process exec = Runtime.getRuntime().exec(command);
//int i = exec.waitFor();
//System.out.println("执行结果:" + i);
...
...
@@ -194,29 +184,30 @@ public class MavenDeployLocalFile {
}
/**
*
写出到文件
*
判断packing是不是pom
*
* @author fengshuonan
* @Date 2018/11/1
8 1:04
PM
* @Date 2018/11/1
9 12:25
PM
*/
private
void
writeToFile
(
String
path
,
List
<
String
>
lists
)
{
File
file
=
new
File
(
path
);
FileWriter
fileWriter
=
null
;
public
static
boolean
packingIsPom
(
File
pom
)
{
BufferedReader
reader
=
null
;
try
{
fileWriter
=
new
FileWriter
(
file
);
for
(
String
list
:
lists
)
{
fileWriter
.
write
(
list
+
"\n"
);
reader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
pom
)));
String
line
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
if
(
line
.
trim
().
contains
(
"<packaging>pom</packaging>"
))
{
return
true
;
}
}
fileWriter
.
flush
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
fileWriter
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
reader
.
close
();
}
catch
(
Exception
e
)
{
}
}
return
false
;
}
/**
...
...
@@ -225,42 +216,45 @@ public class MavenDeployLocalFile {
* @author fengshuonan
* @Date 2018/11/18 11:38 AM
*/
private
String
buildComman
(
FileType
fileType
,
File
deployFile
)
{
private
String
buildComman
(
FileType
fileType
,
File
deployJar
,
File
deployJarPom
)
{
if
(
fileType
.
equals
(
FileType
.
POM
))
{
//判断是不是packing pom
if
(!
packingIsPom
(
deployJarPom
))
{
return
""
;
}
}
String
command
=
"mvn "
+
"-s "
+
SETTINGS_CONFIG
+
" "
+
"deploy:deploy-file "
+
"-Durl="
+
REPOSITORY_URL
+
" "
+
"-DrepositoryId="
+
REPOSITORY_ID
+
" "
;
String
absolutePath
=
deployFile
.
getAbsolutePath
();
String
leaveString
=
absolutePath
.
substring
(
0
,
absolutePath
.
lastIndexOf
(
"/"
));
//获取version
String
version
=
leaveString
.
substring
(
leaveString
.
lastIndexOf
(
"/"
)
+
1
);
leaveString
=
absolutePath
.
substring
(
0
,
leaveString
.
lastIndexOf
(
"/"
));
//获取artifactId
String
artifactId
=
leaveString
.
substring
(
leaveString
.
lastIndexOf
(
"/"
)
+
1
);
leaveString
=
absolutePath
.
substring
(
0
,
leaveString
.
lastIndexOf
(
"/"
));
//获取groupId
leaveString
=
leaveString
.
substring
(
CURRENT_PATH
.
length
());
String
groupId
=
leaveString
.
replaceAll
(
"/"
,
"."
);
"-DrepositoryId="
+
REPOSITORY_ID
+
" "
+
"-DgeneratePom=false "
;
//获取packing
String
packing
;
if
(
fileType
.
equals
(
FileType
.
JAR
))
{
packing
=
"-Dpackaging=jar "
;
}
else
{
packing
=
"-Dpackaging=pom "
;
packing
=
" "
;
}
//获取pomFile和file
String
pomFile
;
String
file
;
if
(
fileType
.
equals
(
FileType
.
POM
))
{
file
=
deployJarPom
.
getAbsolutePath
();
pomFile
=
deployJarPom
.
getAbsolutePath
();
}
else
{
pomFile
=
deployJarPom
.
getAbsolutePath
();
file
=
deployJar
.
getAbsolutePath
();
}
command
+=
packing
;
command
+=
" -Dfile="
+
deployFile
.
getAbsolutePath
()
+
" "
;
command
+=
" -DgroupId="
+
groupId
+
" "
;
command
+=
" -DartifactId="
+
artifactId
+
" "
;
command
+=
" -Dversion="
+
version
+
" "
;
command
+=
" -Dfile="
+
file
+
" "
;
command
+=
" -DpomFile="
+
pomFile
+
" "
;
return
command
;
}
...
...
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