Download Artifactory,JDK
Because in artifactory package, tomcat is included, so we don't need to download tomcat again.
Environment Variable configuration
vi ~/.bashrc
#add configurations below
export JAVA_HOME=/home/local/BROCELIA/zhli/Downloads/jdk1.8.0_201
export PATH=$PATH:/home/local/BROCELIA/zhli/Downloads/jdk1.8.0_201/bin
export JAVA_OPTS=-Dartifactory.home=/home/local/BROCELIA/zhli/Downloads/artifactory-pro-6.8.2
export CATALINA_HOME=/home/local/BROCELIA/zhli/Downloads/apache-tomcat-7.0.93
export ARTIFACTORY_HOME=/home/local/BROCELIA/zhli/Downloads/artifactory-pro-6.8.2
export GRADLE_HOME=/home/local/BROCELIA/zhli/Downloads/gradle-5.2.1
export PATH=$PATH:/home/local/BROCELIA/zhli/Downloads/gradle-5.2.1/bin
复制代码
"esc + :"" and type wq for save and exit vim
source ~/.bashrc
复制代码
In order to save the modification of the vim, must use source command to make it valid
echo $JAVA_HOME
echo $ARTIFACTORY_HOME
复制代码
To show if we have already saved the new environment variable or not
Setting Java Memory Parameters
#!/bin/sh
#Default values
#export ARTIFACTORY_HOME=/var/opt/jfrog/artifactory
#export ARTIFACTORY_USER=artifactory
#export JAVA_HOME=/opt/java/1.8.0
#export START_LOCAL_REPLICATOR=true
#export START_LOCAL_MDS=true
export TOMCAT_HOME=$ARTIFACTORY_HOME/tomcat
export ARTIFACTORY_PID=$ARTIFACTORY_HOME/run/artifactory.pid
export JAVA_OPTIONS="-server -Xms512m -Xmx2g -Xss256k -XX:+UseG1GC -XX:OnOutOfMemoryError=\"kill -9 %p\""
export JAVA_OPTIONS="$JAVA_OPTIONS -Djruby.bytecode.version=1.8 -Djruby.compile.invokedynamic=false -Dfile.encoding=UTF8 -Dartdist=zip -Dorg.apache.tomcat\
.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true -Djava.security.egd=file:/dev/./urandom"
export JAVA_OPTIONS="-server -Xms512m -Xmx2g -Xss256k -XX:PermSize=128m -XX:MaxPermSize=256m -XX:+UseG1GC"
复制代码
For a service installation, modify JAVA_OPTIONS in $ARTIFACTORY_HOME/etc/default
For an RPM or Debian installation, modify JAVA_OPTIONS in /etc/opt/jfrog/artifactory/default
Finally open the artifactory server in the folder of artifactory
sudo $ARTIFACTORY_HOME/bin/artifactory.sh
复制代码
Change port of server (optional if 8080 already been used)
Check port in linux use:
sudo lsof -i -P -n | grep LISTEN
复制代码
If 8080 port already been used, go to $ARTIFACTORY_HOME/tomcat/conf/server.xml, open it and modify the corresponding part of server from 8080 to whatever
<Server port="8015" shutdown="SHUTDOWN">
<Service name="Catalina">
<Connector port="8888" sendReasonPhrase="true" relaxedPathChars='[]' relaxedQueryChars='[]'/>
<Connector port="8887" sendReasonPhrase="true" maxThreads="50"/>
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps" startStopThreads="2">
<Context path="" crossContext="true" docBase="${artifactory.home}/webapps/artifactory.war" processTlds="false">
<Manager pathname="" />
</Context>
</Host>
</Engine>
</Service>
</Server>
复制代码
now the port of artifactory server is 8888, then we restart the PC and open the server again
navigate to http://localhost:8888/ or http://localhost:8888/artifactory, we can go into the artifactory home page
see tuto in www.jfrog.com/confluence/…
Go to the libs-release-local, and click set me up, click Generate settings to download the settings.xml file. Then copy the settings.xml file into user/.m2 folder. Copy the code below in Deploy into pom.xml file.
<distributionManagement>
<repository>
<id>central</id>
<name>fedelini-releases</name>
<url>http://localhost:8888/libs-release-local</url>
</repository>
</distributionManagement>
复制代码
Finally use mvn clean deploy
to update the lib to the artifactory server.
For Projects already use Gradle and Android Studio
In build.gradle of project, add:
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.9.3"
复制代码
In build.gradle of module, type in:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'maven'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.willowtreeapps.hyperion:hyperion-core:0.9.27'
implementation 'com.willowtreeapps.hyperion:hyperion-attr:0.9.27'
implementation 'com.willowtreeapps.hyperion:hyperion-measurement:0.9.27'
implementation 'com.willowtreeapps.hyperion:hyperion-disk:0.9.27'
implementation 'com.willowtreeapps.hyperion:hyperion-recorder:0.9.27'
implementation 'com.willowtreeapps.hyperion:hyperion-phoenix:0.9.27'
implementation 'com.willowtreeapps.hyperion:hyperion-crash:0.9.27'
implementation 'com.willowtreeapps.hyperion:hyperion-shared-preferences:0.9.27'
implementation 'com.willowtreeapps.hyperion:hyperion-geiger-counter:0.9.27'
implementation 'com.willowtreeapps.hyperion:hyperion-timber:0.9.27'
implementation 'com.willowtreeapps.hyperion:hyperion-build-config:0.9.27'
implementation 'org.apache.commons:commons-lang3:3.0'
implementation 'org.slf4j:slf4j-api:1.7.25'
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation files('libs/zip4j_1.3.2.jar')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
def packageName = 'com.brocelia.debugtool'
def libraryVersion = '1.0.0'
publishing {
publications {
aar(MavenPublication) {
groupId packageName
version = libraryVersion
artifactId project.getName()
// Tell maven to prepare the generated "*.aar" file for publishing
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.releaseCompileClasspath.allDependencies.each{ dependency ->
if (dependency.group != null && dependency.name != null) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dependency.group)
dependencyNode.appendNode('artifactId', dependency.name)
dependencyNode.appendNode('version', dependency.version)
}
}
}
}
}
}
artifactory {
contextUrl = 'http://localhost:8888/'
publish {
repository {
// The Artifactory repository key to publish to
repoKey = libraryVersion.endsWith('SNAPSHOT') ? 'libs-snapshot-local' : 'libs-release-local'
username = artifactory_username
password = artifactory_password
}
defaults {
// Tell the Artifactory Plugin which artifacts should be published to Artifactory.
publications('aar')
publishArtifacts = true
// Properties to be attached to the published artifacts.
properties = ['qa.level': 'basic', 'dev.team': 'core']
// Publish generated POM files to Artifactory (true by default)
publishPom = true
}
}
}
repositories {
mavenCentral()
}
复制代码
clean project, in Gradle Task(control bar in right side) run:
other -> assambleRelease (to create and get the aar file)
run publishing -> artifactoryPublish (create pom.xml file and publish to repository in artifactory)
The part below is to generate pom file and add all the remote dependencies inside
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.releaseCompileClasspath.allDependencies.each{ dependency ->
if (dependency.group != null && dependency.name != null) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dependency.group)
dependencyNode.appendNode('artifactId', dependency.name)
dependencyNode.appendNode('version', dependency.version)
}
}
}
复制代码
The main problem of this part of code is happened in configurations.releaseCompileClasspath.allDependencies.each
, in order to fetch all the dependencies, we need to add this part into publishing, for versions of Gradle after 4,configurations.compile
will not be compiled, need to use configurations.releaseCompileClasspath
.
repository {
// The Artifactory repository key to publish to
repoKey = libraryVersion.endsWith('SNAPSHOT') ? 'libs-snapshot-local' : 'libs-release-local'
username = artifactory_username
password = artifactory_password
}
复制代码
The part below is to get the access to the Artifactory repository, the repokey is the corresponding repository, if the version is end with SNAPSHOT, we connect the libs-snapshot-loacl, if not we connect libs-release-local. The username and password are configured in the "gradle.properties" file like:
artifactory_username=admin
artifactory_password=brocelia
复制代码
To check the files have been created in the project after run "artifactoryPublish"
Project -> module -> build -> outputs -> aar -> projectname-release.aar
Project -> module -> build -> publications -> aar -> pom-default.xml
The maven repository after published are shown below.
To use the maven libs in Artifactory server
- In build.gradle of project, add
maven { url "http://localhost:8888/libs-release-local" }
. - In build.gradle of application,
add implementation 'com.brocelia.testmaven:maventest:1.0.0'
. - Run Rebuild Project.
In Real project, how to configure the DebugTool and custome options
1. Configure DebugTool
In order to show the dialog list of DebugTool, we need to use a fragment to package the tool.
In this case, we create a fragment.xml resource file and a MainFragment.kt class file, code shown below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:gravity="center"/>
</RelativeLayout>
复制代码
@file:Suppress("DEPRECATION")
package com.example.myapplication
import android.annotation.SuppressLint
import android.app.Fragment
import android.os.Build
import android.os.Bundle
import android.support.annotation.RequiresApi
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import com.example.myutils.DebugTool
import com.example.myutils.OptionListener
import com.example.myutils.testClass
import io.realm.Realm
import java.io.File
import java.util.*
@Suppress("DEPRECATION", "NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS",
"RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS"
)
open class MainFragment : Fragment() {
private lateinit var mView: View
private lateinit var text : TextView
@SuppressLint("SetTextI18n")
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
mView = inflater.inflate(R.layout.fragment, container, false)
text = mView.findViewById(R.id.textView)
val exportRealmFile : File? = File(activity.externalCacheDir, "export.realm")
exportRealmFile?.delete()
Realm.getDefaultInstance()!!.writeCopyTo(exportRealmFile) // get the DB file and pass the path to the Debug
val calendar = Calendar.getInstance()
val date = calendar.get(Calendar.YEAR).toString()+'-'+(calendar.get(Calendar.MONTH)+1).toString()+'-'+calendar.get(Calendar.DAY_OF_MONTH).toString()
val logcat = File(activity.externalCacheDir,"base.log.$date.log") // get the log file and pass the path to the Debug
val debugTool = DebugTool(mView.rootView,activity,exportRealmFile!!.path,logcat.path,"li@brocelia.fr","brocelia")
return mView
}
}
复制代码
Then add a FrameLayout in the Activity we need to show DebugTool dialog like:
<FrameLayout
android:id="@+id/fragmentLayout"
android:layout_width="0dp"
android:layout_height="0dp" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
复制代码
As we can see, we initialize the DebugTool in MainFragment, and we can also initialize the database path and logcat path here as well.
Until now, preparation has finished and we just need to add the fragment in the activities which we need to run the DebugTool.
For example, we need two activities need to lanch DebugTool, so in this case we add code separately to the Activities like:
fragmentManager.beginTransaction().replace(R.id.fragmentLayout, MainFragment()).addToBackStack(null).commit()
//in MainActivity
fragmentManager.beginTransaction().replace(R.id.secondfragmentLayout, MainFragment()).addToBackStack(null).commit()
//in second Activity
复制代码
Here in replace() function we need a framelayout to assign a place for fragment to show, moreover the fragment is needed to be shown. Of course here we just need to reuse the MainFragment whenever we want to show the DebugTool dialog.
2. Customize options
After initialized the debugtool variable, just use the already defined funtion AddOptions to add new functions to the list of DebugTool like:
debugTool.AddOptions("option1", object : OptionListener {
override fun onClickOption(item: String, position: Int) {
Toast.makeText(activity, "this option is $item", Toast.LENGTH_LONG).show()
}
})
debugTool.AddOptions("option2", object : OptionListener {
override fun onClickOption(item: String, position: Int) {
Toast.makeText(activity, "this is the ${position+1} option", Toast.LENGTH_LONG).show()
}
})
复制代码
Then we will get two new options in the DebugTool list.